Shell – Multiline command : comment out one line

scriptingshellshell-script

I like to use the following format in scripts for commands with a lot of parameters (for readability):

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

But, sometimes I'd like to comment one of these parameters out like:

# -p 8080:8080  

This doesn't work, as the EOL is interpreted as return and the command fails. Tried this too:

\ # -p 8080:8080

which also didn't work.

Question: Is there a way to comment out the parameter, so it's still on its own line, but I'd be able to execute the script?

Best Answer

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
Related Question