Multiline command : comment out one line
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
add a comment |
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
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
add a comment |
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
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
shell-script shell scripting
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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[@]}"
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
add a comment |
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
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 betrue
– Jeff Schaller
Feb 6 at 20:27
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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[@]}"
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
add a comment |
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[@]}"
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
add a comment |
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 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[@]}"
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
add a comment |
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
add a comment |
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
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 betrue
– Jeff Schaller
Feb 6 at 20:27
add a comment |
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
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 betrue
– Jeff Schaller
Feb 6 at 20:27
add a comment |
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
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
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 betrue
– Jeff Schaller
Feb 6 at 20:27
add a comment |
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 betrue
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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