Multiline command : comment out one line












7















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?










share|improve this question























  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!

    – Jeff Schaller
    Feb 17 at 13:46
















7















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?










share|improve this question























  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!

    – Jeff Schaller
    Feb 17 at 13:46














7












7








7








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?










share|improve this question














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?







shell-script shell scripting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 6 at 15:46









ChirloChirlo

25816




25816













  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!

    – Jeff Schaller
    Feb 17 at 13:46



















  • If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!

    – Jeff Schaller
    Feb 17 at 13:46

















If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!

– Jeff Schaller
Feb 17 at 13:46





If any of the answers solved your problem, please accept it by clicking the checkmark next to it. Thank you!

– Jeff Schaller
Feb 17 at 13:46










2 Answers
2






active

oldest

votes


















11














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[@]}"





share|improve this answer





















  • 5





    Putting all the arguments in an array is also a great way to do it, since you can have a multi-line array definition with no ``s and you can comment individual lines... Wanna include that into your answer too?

    – filbranden
    Feb 6 at 16:02








  • 1





    @filbranden Will do as it's a good extension of what I already had written. Thanks.

    – Kusalananda
    Feb 6 at 16:04



















8














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





share|improve this answer
























  • Not very readable (and Vim doesn't recognise : as the empty command or a comment) but works.

    – tricasse
    Feb 6 at 18:07











  • I like that with this solution I can still copy it with the mouse, paste it and run it. Now just need a vi macro to be able to do/undo this change easy, thanks!

    – Chirlo
    Feb 6 at 18:36











  • @tricasse an alternative to : would be true

    – Jeff Schaller
    Feb 6 at 20:27











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499081%2fmultiline-command-comment-out-one-line%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









11














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[@]}"





share|improve this answer





















  • 5





    Putting all the arguments in an array is also a great way to do it, since you can have a multi-line array definition with no ``s and you can comment individual lines... Wanna include that into your answer too?

    – filbranden
    Feb 6 at 16:02








  • 1





    @filbranden Will do as it's a good extension of what I already had written. Thanks.

    – Kusalananda
    Feb 6 at 16:04
















11














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[@]}"





share|improve this answer





















  • 5





    Putting all the arguments in an array is also a great way to do it, since you can have a multi-line array definition with no ``s and you can comment individual lines... Wanna include that into your answer too?

    – filbranden
    Feb 6 at 16:02








  • 1





    @filbranden Will do as it's a good extension of what I already had written. Thanks.

    – Kusalananda
    Feb 6 at 16:04














11












11








11







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[@]}"





share|improve this answer















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[@]}"






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 6 at 16:06

























answered Feb 6 at 15:57









KusalanandaKusalananda

134k17254418




134k17254418








  • 5





    Putting all the arguments in an array is also a great way to do it, since you can have a multi-line array definition with no ``s and you can comment individual lines... Wanna include that into your answer too?

    – filbranden
    Feb 6 at 16:02








  • 1





    @filbranden Will do as it's a good extension of what I already had written. Thanks.

    – Kusalananda
    Feb 6 at 16:04














  • 5





    Putting all the arguments in an array is also a great way to do it, since you can have a multi-line array definition with no ``s and you can comment individual lines... Wanna include that into your answer too?

    – filbranden
    Feb 6 at 16:02








  • 1





    @filbranden Will do as it's a good extension of what I already had written. Thanks.

    – Kusalananda
    Feb 6 at 16:04








5




5





Putting all the arguments in an array is also a great way to do it, since you can have a multi-line array definition with no ``s and you can comment individual lines... Wanna include that into your answer too?

– filbranden
Feb 6 at 16:02







Putting all the arguments in an array is also a great way to do it, since you can have a multi-line array definition with no ``s and you can comment individual lines... Wanna include that into your answer too?

– filbranden
Feb 6 at 16:02






1




1





@filbranden Will do as it's a good extension of what I already had written. Thanks.

– Kusalananda
Feb 6 at 16:04





@filbranden Will do as it's a good extension of what I already had written. Thanks.

– Kusalananda
Feb 6 at 16:04













8














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





share|improve this answer
























  • Not very readable (and Vim doesn't recognise : as the empty command or a comment) but works.

    – tricasse
    Feb 6 at 18:07











  • I like that with this solution I can still copy it with the mouse, paste it and run it. Now just need a vi macro to be able to do/undo this change easy, thanks!

    – Chirlo
    Feb 6 at 18:36











  • @tricasse an alternative to : would be true

    – Jeff Schaller
    Feb 6 at 20:27
















8














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





share|improve this answer
























  • Not very readable (and Vim doesn't recognise : as the empty command or a comment) but works.

    – tricasse
    Feb 6 at 18:07











  • I like that with this solution I can still copy it with the mouse, paste it and run it. Now just need a vi macro to be able to do/undo this change easy, thanks!

    – Chirlo
    Feb 6 at 18:36











  • @tricasse an alternative to : would be true

    – Jeff Schaller
    Feb 6 at 20:27














8












8








8







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





share|improve this 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






share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 6 at 16:01









Jeff SchallerJeff Schaller

42.9k1159137




42.9k1159137













  • Not very readable (and Vim doesn't recognise : as the empty command or a comment) but works.

    – tricasse
    Feb 6 at 18:07











  • I like that with this solution I can still copy it with the mouse, paste it and run it. Now just need a vi macro to be able to do/undo this change easy, thanks!

    – Chirlo
    Feb 6 at 18:36











  • @tricasse an alternative to : would be true

    – Jeff Schaller
    Feb 6 at 20:27



















  • Not very readable (and Vim doesn't recognise : as the empty command or a comment) but works.

    – tricasse
    Feb 6 at 18:07











  • I like that with this solution I can still copy it with the mouse, paste it and run it. Now just need a vi macro to be able to do/undo this change easy, thanks!

    – Chirlo
    Feb 6 at 18:36











  • @tricasse an alternative to : would be true

    – Jeff Schaller
    Feb 6 at 20:27

















Not very readable (and Vim doesn't recognise : as the empty command or a comment) but works.

– tricasse
Feb 6 at 18:07





Not very readable (and Vim doesn't recognise : as the empty command or a comment) but works.

– tricasse
Feb 6 at 18:07













I like that with this solution I can still copy it with the mouse, paste it and run it. Now just need a vi macro to be able to do/undo this change easy, thanks!

– Chirlo
Feb 6 at 18:36





I like that with this solution I can still copy it with the mouse, paste it and run it. Now just need a vi macro to be able to do/undo this change easy, thanks!

– Chirlo
Feb 6 at 18:36













@tricasse an alternative to : would be true

– Jeff Schaller
Feb 6 at 20:27





@tricasse an alternative to : would be true

– Jeff Schaller
Feb 6 at 20:27


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499081%2fmultiline-command-comment-out-one-line%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How do I know what Microsoft account the skydrive app is syncing to?

Grease: Live!

When does type information flow backwards in C++?