Multiline command : comment out one line
You can't comment out a piece of a line.
Note that since the newlines are escaped, the command is actually a single line (to the shell parser), and there's no way to comment out a part of a single line (except for at the very end).
Instead, maybe just make a copy of the original command in an editor and comment it out completely while keeping the modified command uncommented:
docker run \
--rm \
-u root \
-v jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$HOME":/home \
jenkinsci/blueocean
# Was originally:
# docker run \
# --rm \
# -u root \
# -p 8080:8080 \
# -v jenkins-data:/var/jenkins_home \
# -v /var/run/docker.sock:/var/run/docker.sock \
# -v "$HOME":/home \
# jenkinsci/blueocean
Alternatively, if you want to occasionally delete or change the -p
option and its argument (assuming bash
or a shell with the same array syntax):
port=( -p 8080:8080 )
docker run \
--rm \
-u root \
"${port[@]}" \
-v jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$HOME":/home \
jenkinsci/blueocean
Then just change or comment out the assignment to port
.
Taking this further:
docker_run_args=(
--rm
-u root
-p 8080:8080
-v jenkins-data:/var/jenkins_home
-v /var/run/docker.sock:/var/run/docker.sock
-v "$HOME":/home
jenkinsci/blueocean
)
docker run "${docker_run_args[@]}"
Inside the array assignment, there are no issues with commenting out a line:
docker_run_args=(
--rm
-u root
# -p 8080:8080
-v jenkins-data:/var/jenkins_home
-v /var/run/docker.sock:/var/run/docker.sock
-v "$HOME":/home
jenkinsci/blueocean
)
docker run "${docker_run_args[@]}"
You could substitute an empty command substitution:
docker run \
--rm \
-u root \
$(: -p 8080:8080 ) \
-v jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$HOME":/home \
jenkinsci/blueocean