Display a text message when running a specific command
Sometimes, after I run some commands (for example git
commands), I discover that I forgot some configurations or forgot to put some requirements... . So I thought about displaying a message, to remind me or warn me, (like the one displayed when we run sudo apt upgrade
:
The following packages will be upgraded ... Do you want to continue [Y/n]?)
I want to get a similar message when I run a specific command ("Did you check the conf files, did you update the requirements file?) When I type Y, the command run and when I type n, the command stops.
How to do this in Ubuntu?
command-line
add a comment |
Sometimes, after I run some commands (for example git
commands), I discover that I forgot some configurations or forgot to put some requirements... . So I thought about displaying a message, to remind me or warn me, (like the one displayed when we run sudo apt upgrade
:
The following packages will be upgraded ... Do you want to continue [Y/n]?)
I want to get a similar message when I run a specific command ("Did you check the conf files, did you update the requirements file?) When I type Y, the command run and when I type n, the command stops.
How to do this in Ubuntu?
command-line
add a comment |
Sometimes, after I run some commands (for example git
commands), I discover that I forgot some configurations or forgot to put some requirements... . So I thought about displaying a message, to remind me or warn me, (like the one displayed when we run sudo apt upgrade
:
The following packages will be upgraded ... Do you want to continue [Y/n]?)
I want to get a similar message when I run a specific command ("Did you check the conf files, did you update the requirements file?) When I type Y, the command run and when I type n, the command stops.
How to do this in Ubuntu?
command-line
Sometimes, after I run some commands (for example git
commands), I discover that I forgot some configurations or forgot to put some requirements... . So I thought about displaying a message, to remind me or warn me, (like the one displayed when we run sudo apt upgrade
:
The following packages will be upgraded ... Do you want to continue [Y/n]?)
I want to get a similar message when I run a specific command ("Did you check the conf files, did you update the requirements file?) When I type Y, the command run and when I type n, the command stops.
How to do this in Ubuntu?
command-line
command-line
asked Dec 19 '18 at 10:56
singrium
1,025321
1,025321
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Typically, when there are things that have to be done before an actual command runs - such as providing and setting up environment variables, adding extra positional parameters, etc - the command is placed into a wrapper script. How it should be implemented - that depends on the specific command you want and things you want to check before actual command runs. In the very simple case such as git
, you could do something along the following lines:
#!/bin/sh
printf "%sn" "Did you check the conf files, did you update the requirements file?[y/n]"
read answer
case "$answer" in
[Yy]) exec git commit -a ;;
[Nn]) printf "%sn" "Please check. Exiting"; exit 1 ;;
esac
Of course the next question is the naming of the command. This script could be named git-commit
or something similar. I would advice against naming wrapper scripts same as the original application.
See also:
- In Bash, how to add “Are you sure [Y/n]” to any command or alias?
- Add flag to existing terminal command
1
+1 nice touch adding references to sister-site. I would note best to use "Y" to proceed, any other key to exit. Currently if user presses "U" neither "Y" nor "N" is executed.
– WinEunuuchs2Unix
Dec 19 '18 at 11:27
1
@WinEunuuchs2Unix Agreed, that's a better approach. I'll try to remember that for the future
– Sergiy Kolodyazhnyy
Dec 19 '18 at 11:29
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f1103086%2fdisplay-a-text-message-when-running-a-specific-command%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Typically, when there are things that have to be done before an actual command runs - such as providing and setting up environment variables, adding extra positional parameters, etc - the command is placed into a wrapper script. How it should be implemented - that depends on the specific command you want and things you want to check before actual command runs. In the very simple case such as git
, you could do something along the following lines:
#!/bin/sh
printf "%sn" "Did you check the conf files, did you update the requirements file?[y/n]"
read answer
case "$answer" in
[Yy]) exec git commit -a ;;
[Nn]) printf "%sn" "Please check. Exiting"; exit 1 ;;
esac
Of course the next question is the naming of the command. This script could be named git-commit
or something similar. I would advice against naming wrapper scripts same as the original application.
See also:
- In Bash, how to add “Are you sure [Y/n]” to any command or alias?
- Add flag to existing terminal command
1
+1 nice touch adding references to sister-site. I would note best to use "Y" to proceed, any other key to exit. Currently if user presses "U" neither "Y" nor "N" is executed.
– WinEunuuchs2Unix
Dec 19 '18 at 11:27
1
@WinEunuuchs2Unix Agreed, that's a better approach. I'll try to remember that for the future
– Sergiy Kolodyazhnyy
Dec 19 '18 at 11:29
add a comment |
Typically, when there are things that have to be done before an actual command runs - such as providing and setting up environment variables, adding extra positional parameters, etc - the command is placed into a wrapper script. How it should be implemented - that depends on the specific command you want and things you want to check before actual command runs. In the very simple case such as git
, you could do something along the following lines:
#!/bin/sh
printf "%sn" "Did you check the conf files, did you update the requirements file?[y/n]"
read answer
case "$answer" in
[Yy]) exec git commit -a ;;
[Nn]) printf "%sn" "Please check. Exiting"; exit 1 ;;
esac
Of course the next question is the naming of the command. This script could be named git-commit
or something similar. I would advice against naming wrapper scripts same as the original application.
See also:
- In Bash, how to add “Are you sure [Y/n]” to any command or alias?
- Add flag to existing terminal command
1
+1 nice touch adding references to sister-site. I would note best to use "Y" to proceed, any other key to exit. Currently if user presses "U" neither "Y" nor "N" is executed.
– WinEunuuchs2Unix
Dec 19 '18 at 11:27
1
@WinEunuuchs2Unix Agreed, that's a better approach. I'll try to remember that for the future
– Sergiy Kolodyazhnyy
Dec 19 '18 at 11:29
add a comment |
Typically, when there are things that have to be done before an actual command runs - such as providing and setting up environment variables, adding extra positional parameters, etc - the command is placed into a wrapper script. How it should be implemented - that depends on the specific command you want and things you want to check before actual command runs. In the very simple case such as git
, you could do something along the following lines:
#!/bin/sh
printf "%sn" "Did you check the conf files, did you update the requirements file?[y/n]"
read answer
case "$answer" in
[Yy]) exec git commit -a ;;
[Nn]) printf "%sn" "Please check. Exiting"; exit 1 ;;
esac
Of course the next question is the naming of the command. This script could be named git-commit
or something similar. I would advice against naming wrapper scripts same as the original application.
See also:
- In Bash, how to add “Are you sure [Y/n]” to any command or alias?
- Add flag to existing terminal command
Typically, when there are things that have to be done before an actual command runs - such as providing and setting up environment variables, adding extra positional parameters, etc - the command is placed into a wrapper script. How it should be implemented - that depends on the specific command you want and things you want to check before actual command runs. In the very simple case such as git
, you could do something along the following lines:
#!/bin/sh
printf "%sn" "Did you check the conf files, did you update the requirements file?[y/n]"
read answer
case "$answer" in
[Yy]) exec git commit -a ;;
[Nn]) printf "%sn" "Please check. Exiting"; exit 1 ;;
esac
Of course the next question is the naming of the command. This script could be named git-commit
or something similar. I would advice against naming wrapper scripts same as the original application.
See also:
- In Bash, how to add “Are you sure [Y/n]” to any command or alias?
- Add flag to existing terminal command
edited Dec 19 '18 at 11:17
answered Dec 19 '18 at 11:11
Sergiy Kolodyazhnyy
69.5k9144306
69.5k9144306
1
+1 nice touch adding references to sister-site. I would note best to use "Y" to proceed, any other key to exit. Currently if user presses "U" neither "Y" nor "N" is executed.
– WinEunuuchs2Unix
Dec 19 '18 at 11:27
1
@WinEunuuchs2Unix Agreed, that's a better approach. I'll try to remember that for the future
– Sergiy Kolodyazhnyy
Dec 19 '18 at 11:29
add a comment |
1
+1 nice touch adding references to sister-site. I would note best to use "Y" to proceed, any other key to exit. Currently if user presses "U" neither "Y" nor "N" is executed.
– WinEunuuchs2Unix
Dec 19 '18 at 11:27
1
@WinEunuuchs2Unix Agreed, that's a better approach. I'll try to remember that for the future
– Sergiy Kolodyazhnyy
Dec 19 '18 at 11:29
1
1
+1 nice touch adding references to sister-site. I would note best to use "Y" to proceed, any other key to exit. Currently if user presses "U" neither "Y" nor "N" is executed.
– WinEunuuchs2Unix
Dec 19 '18 at 11:27
+1 nice touch adding references to sister-site. I would note best to use "Y" to proceed, any other key to exit. Currently if user presses "U" neither "Y" nor "N" is executed.
– WinEunuuchs2Unix
Dec 19 '18 at 11:27
1
1
@WinEunuuchs2Unix Agreed, that's a better approach. I'll try to remember that for the future
– Sergiy Kolodyazhnyy
Dec 19 '18 at 11:29
@WinEunuuchs2Unix Agreed, that's a better approach. I'll try to remember that for the future
– Sergiy Kolodyazhnyy
Dec 19 '18 at 11:29
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2faskubuntu.com%2fquestions%2f1103086%2fdisplay-a-text-message-when-running-a-specific-command%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