Is $PROMPT_COMMAND a colon separated list?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I want to enable my command history across all terminal tabs and windows to be recorded in .bash_history by setting PROMPT_COMMAND in .profile:



  1. export PROMPT_COMMAND="history -a; history -c; history -r;$PROMPT_COMMAND"

However, when I check whether this environment variable is already set, I get:



echo $PROMPT_COMMAND
printf "33]0;%s@%s:%s07" "$USER" "$HOSTNAME%%.*" "$PWD/#$HOME/~"


Will exporting PROMPT_COMMAND like this overwrite my existing $PROMPT_COMMAND list or is it necessary to prefix the value of PROMPT_COMMAND with a : before exporting it?







share|improve this question





















  • It's a command. It has to look like a command. A colon will make it not look like a command.
    – Ignacio Vazquez-Abrams
    yesterday










  • @IgnacioVazquez-Abrams thanks for confirming that. How do I use PROMPT_COMMAND without overwritting the one that is already set or does it not overate since it is not a colon separated list?
    – MyWrathAcademia
    yesterday

















up vote
1
down vote

favorite












I want to enable my command history across all terminal tabs and windows to be recorded in .bash_history by setting PROMPT_COMMAND in .profile:



  1. export PROMPT_COMMAND="history -a; history -c; history -r;$PROMPT_COMMAND"

However, when I check whether this environment variable is already set, I get:



echo $PROMPT_COMMAND
printf "33]0;%s@%s:%s07" "$USER" "$HOSTNAME%%.*" "$PWD/#$HOME/~"


Will exporting PROMPT_COMMAND like this overwrite my existing $PROMPT_COMMAND list or is it necessary to prefix the value of PROMPT_COMMAND with a : before exporting it?







share|improve this question





















  • It's a command. It has to look like a command. A colon will make it not look like a command.
    – Ignacio Vazquez-Abrams
    yesterday










  • @IgnacioVazquez-Abrams thanks for confirming that. How do I use PROMPT_COMMAND without overwritting the one that is already set or does it not overate since it is not a colon separated list?
    – MyWrathAcademia
    yesterday













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to enable my command history across all terminal tabs and windows to be recorded in .bash_history by setting PROMPT_COMMAND in .profile:



  1. export PROMPT_COMMAND="history -a; history -c; history -r;$PROMPT_COMMAND"

However, when I check whether this environment variable is already set, I get:



echo $PROMPT_COMMAND
printf "33]0;%s@%s:%s07" "$USER" "$HOSTNAME%%.*" "$PWD/#$HOME/~"


Will exporting PROMPT_COMMAND like this overwrite my existing $PROMPT_COMMAND list or is it necessary to prefix the value of PROMPT_COMMAND with a : before exporting it?







share|improve this question













I want to enable my command history across all terminal tabs and windows to be recorded in .bash_history by setting PROMPT_COMMAND in .profile:



  1. export PROMPT_COMMAND="history -a; history -c; history -r;$PROMPT_COMMAND"

However, when I check whether this environment variable is already set, I get:



echo $PROMPT_COMMAND
printf "33]0;%s@%s:%s07" "$USER" "$HOSTNAME%%.*" "$PWD/#$HOME/~"


Will exporting PROMPT_COMMAND like this overwrite my existing $PROMPT_COMMAND list or is it necessary to prefix the value of PROMPT_COMMAND with a : before exporting it?









share|improve this question












share|improve this question




share|improve this question








edited yesterday









Kusalananda

100k13199311




100k13199311









asked yesterday









MyWrathAcademia

1369




1369











  • It's a command. It has to look like a command. A colon will make it not look like a command.
    – Ignacio Vazquez-Abrams
    yesterday










  • @IgnacioVazquez-Abrams thanks for confirming that. How do I use PROMPT_COMMAND without overwritting the one that is already set or does it not overate since it is not a colon separated list?
    – MyWrathAcademia
    yesterday

















  • It's a command. It has to look like a command. A colon will make it not look like a command.
    – Ignacio Vazquez-Abrams
    yesterday










  • @IgnacioVazquez-Abrams thanks for confirming that. How do I use PROMPT_COMMAND without overwritting the one that is already set or does it not overate since it is not a colon separated list?
    – MyWrathAcademia
    yesterday
















It's a command. It has to look like a command. A colon will make it not look like a command.
– Ignacio Vazquez-Abrams
yesterday




It's a command. It has to look like a command. A colon will make it not look like a command.
– Ignacio Vazquez-Abrams
yesterday












@IgnacioVazquez-Abrams thanks for confirming that. How do I use PROMPT_COMMAND without overwritting the one that is already set or does it not overate since it is not a colon separated list?
– MyWrathAcademia
yesterday





@IgnacioVazquez-Abrams thanks for confirming that. How do I use PROMPT_COMMAND without overwritting the one that is already set or does it not overate since it is not a colon separated list?
– MyWrathAcademia
yesterday











1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted











Is $PROMPT_COMMAND a colon separated list?




That's easy enough to test:



$ PROMPT_COMMAND='true:true' bash 
bash: true:true: command not found
$ exit


So, the answer is "no".



But you could take it as a semicolon separated sequence of commands, as any other line of shell code:



$ PROMPT_COMMAND='echo x;echo y' bash 
x
y
$ exit


That's what the assignment in your question has: a number of commands, separated by semicolons, with the earlier value of PROMPT_COMMAND tacked on to the end.



Of course, another way to run multiple commands from PROMPT_COMMAND, would be to make a function and call it from there.



That said, the printf sequence in your PROMPT_COMMAND looks like something that might be better placed in the actual prompt instead, for two reasons. First, it doesn't end in a newline, so it may mess up Bash's idea of where the cursor is, just like other commands that output incomplete lines before exiting. Second, if you have the shell re-print the prompt, through tab-completion, PS1 will be redisplayed, but PROMPT_COMMAND will not run again.






share|improve this answer























  • Thanks for showing how to test for it, it's very useful, but how do I use PROMPT_COMMAND without overwritting the value that is already set or does it not overwrite since it is not a colon separated list?
    – MyWrathAcademia
    yesterday











  • To touch on your last paragraph, that is the default PROMPT_COMMAND on my fedora system. I have not modified it in any way.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, oh, sorry, that's the escape sequence for setting the window title. That makes more sense; it's not going to be visible on the prompt line. Anyway, the assignment you have should work in adding new commands to PROMPT_COMMAND, the semicolon works as a separator there.
    – ilkkachu
    yesterday










  • Yes, I realise now that environment variables can be a colon separated list of values or a list of commands.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, mmm, well. Colon-separated lists of paths are indeed common (PATH, CDPATH, LD_LIBRARY_PATH, ... though the man page says the last one can also use semicolons as separators(!)). I don't think ones that take commands are that common, but then you have lots and lots of envvars that are really just single values (LANG and all the LC_*, USER, EDITOR...) or single paths (HOME, MAIL...). The wonderful thing is that they can be whatever the command that uses them wants them to be...
    – ilkkachu
    yesterday










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f460651%2fis-prompt-command-a-colon-separated-list%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted











Is $PROMPT_COMMAND a colon separated list?




That's easy enough to test:



$ PROMPT_COMMAND='true:true' bash 
bash: true:true: command not found
$ exit


So, the answer is "no".



But you could take it as a semicolon separated sequence of commands, as any other line of shell code:



$ PROMPT_COMMAND='echo x;echo y' bash 
x
y
$ exit


That's what the assignment in your question has: a number of commands, separated by semicolons, with the earlier value of PROMPT_COMMAND tacked on to the end.



Of course, another way to run multiple commands from PROMPT_COMMAND, would be to make a function and call it from there.



That said, the printf sequence in your PROMPT_COMMAND looks like something that might be better placed in the actual prompt instead, for two reasons. First, it doesn't end in a newline, so it may mess up Bash's idea of where the cursor is, just like other commands that output incomplete lines before exiting. Second, if you have the shell re-print the prompt, through tab-completion, PS1 will be redisplayed, but PROMPT_COMMAND will not run again.






share|improve this answer























  • Thanks for showing how to test for it, it's very useful, but how do I use PROMPT_COMMAND without overwritting the value that is already set or does it not overwrite since it is not a colon separated list?
    – MyWrathAcademia
    yesterday











  • To touch on your last paragraph, that is the default PROMPT_COMMAND on my fedora system. I have not modified it in any way.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, oh, sorry, that's the escape sequence for setting the window title. That makes more sense; it's not going to be visible on the prompt line. Anyway, the assignment you have should work in adding new commands to PROMPT_COMMAND, the semicolon works as a separator there.
    – ilkkachu
    yesterday










  • Yes, I realise now that environment variables can be a colon separated list of values or a list of commands.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, mmm, well. Colon-separated lists of paths are indeed common (PATH, CDPATH, LD_LIBRARY_PATH, ... though the man page says the last one can also use semicolons as separators(!)). I don't think ones that take commands are that common, but then you have lots and lots of envvars that are really just single values (LANG and all the LC_*, USER, EDITOR...) or single paths (HOME, MAIL...). The wonderful thing is that they can be whatever the command that uses them wants them to be...
    – ilkkachu
    yesterday














up vote
1
down vote



accepted











Is $PROMPT_COMMAND a colon separated list?




That's easy enough to test:



$ PROMPT_COMMAND='true:true' bash 
bash: true:true: command not found
$ exit


So, the answer is "no".



But you could take it as a semicolon separated sequence of commands, as any other line of shell code:



$ PROMPT_COMMAND='echo x;echo y' bash 
x
y
$ exit


That's what the assignment in your question has: a number of commands, separated by semicolons, with the earlier value of PROMPT_COMMAND tacked on to the end.



Of course, another way to run multiple commands from PROMPT_COMMAND, would be to make a function and call it from there.



That said, the printf sequence in your PROMPT_COMMAND looks like something that might be better placed in the actual prompt instead, for two reasons. First, it doesn't end in a newline, so it may mess up Bash's idea of where the cursor is, just like other commands that output incomplete lines before exiting. Second, if you have the shell re-print the prompt, through tab-completion, PS1 will be redisplayed, but PROMPT_COMMAND will not run again.






share|improve this answer























  • Thanks for showing how to test for it, it's very useful, but how do I use PROMPT_COMMAND without overwritting the value that is already set or does it not overwrite since it is not a colon separated list?
    – MyWrathAcademia
    yesterday











  • To touch on your last paragraph, that is the default PROMPT_COMMAND on my fedora system. I have not modified it in any way.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, oh, sorry, that's the escape sequence for setting the window title. That makes more sense; it's not going to be visible on the prompt line. Anyway, the assignment you have should work in adding new commands to PROMPT_COMMAND, the semicolon works as a separator there.
    – ilkkachu
    yesterday










  • Yes, I realise now that environment variables can be a colon separated list of values or a list of commands.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, mmm, well. Colon-separated lists of paths are indeed common (PATH, CDPATH, LD_LIBRARY_PATH, ... though the man page says the last one can also use semicolons as separators(!)). I don't think ones that take commands are that common, but then you have lots and lots of envvars that are really just single values (LANG and all the LC_*, USER, EDITOR...) or single paths (HOME, MAIL...). The wonderful thing is that they can be whatever the command that uses them wants them to be...
    – ilkkachu
    yesterday












up vote
1
down vote



accepted







up vote
1
down vote



accepted







Is $PROMPT_COMMAND a colon separated list?




That's easy enough to test:



$ PROMPT_COMMAND='true:true' bash 
bash: true:true: command not found
$ exit


So, the answer is "no".



But you could take it as a semicolon separated sequence of commands, as any other line of shell code:



$ PROMPT_COMMAND='echo x;echo y' bash 
x
y
$ exit


That's what the assignment in your question has: a number of commands, separated by semicolons, with the earlier value of PROMPT_COMMAND tacked on to the end.



Of course, another way to run multiple commands from PROMPT_COMMAND, would be to make a function and call it from there.



That said, the printf sequence in your PROMPT_COMMAND looks like something that might be better placed in the actual prompt instead, for two reasons. First, it doesn't end in a newline, so it may mess up Bash's idea of where the cursor is, just like other commands that output incomplete lines before exiting. Second, if you have the shell re-print the prompt, through tab-completion, PS1 will be redisplayed, but PROMPT_COMMAND will not run again.






share|improve this answer
















Is $PROMPT_COMMAND a colon separated list?




That's easy enough to test:



$ PROMPT_COMMAND='true:true' bash 
bash: true:true: command not found
$ exit


So, the answer is "no".



But you could take it as a semicolon separated sequence of commands, as any other line of shell code:



$ PROMPT_COMMAND='echo x;echo y' bash 
x
y
$ exit


That's what the assignment in your question has: a number of commands, separated by semicolons, with the earlier value of PROMPT_COMMAND tacked on to the end.



Of course, another way to run multiple commands from PROMPT_COMMAND, would be to make a function and call it from there.



That said, the printf sequence in your PROMPT_COMMAND looks like something that might be better placed in the actual prompt instead, for two reasons. First, it doesn't end in a newline, so it may mess up Bash's idea of where the cursor is, just like other commands that output incomplete lines before exiting. Second, if you have the shell re-print the prompt, through tab-completion, PS1 will be redisplayed, but PROMPT_COMMAND will not run again.







share|improve this answer















share|improve this answer



share|improve this answer








edited yesterday


























answered yesterday









ilkkachu

47.3k668130




47.3k668130











  • Thanks for showing how to test for it, it's very useful, but how do I use PROMPT_COMMAND without overwritting the value that is already set or does it not overwrite since it is not a colon separated list?
    – MyWrathAcademia
    yesterday











  • To touch on your last paragraph, that is the default PROMPT_COMMAND on my fedora system. I have not modified it in any way.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, oh, sorry, that's the escape sequence for setting the window title. That makes more sense; it's not going to be visible on the prompt line. Anyway, the assignment you have should work in adding new commands to PROMPT_COMMAND, the semicolon works as a separator there.
    – ilkkachu
    yesterday










  • Yes, I realise now that environment variables can be a colon separated list of values or a list of commands.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, mmm, well. Colon-separated lists of paths are indeed common (PATH, CDPATH, LD_LIBRARY_PATH, ... though the man page says the last one can also use semicolons as separators(!)). I don't think ones that take commands are that common, but then you have lots and lots of envvars that are really just single values (LANG and all the LC_*, USER, EDITOR...) or single paths (HOME, MAIL...). The wonderful thing is that they can be whatever the command that uses them wants them to be...
    – ilkkachu
    yesterday
















  • Thanks for showing how to test for it, it's very useful, but how do I use PROMPT_COMMAND without overwritting the value that is already set or does it not overwrite since it is not a colon separated list?
    – MyWrathAcademia
    yesterday











  • To touch on your last paragraph, that is the default PROMPT_COMMAND on my fedora system. I have not modified it in any way.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, oh, sorry, that's the escape sequence for setting the window title. That makes more sense; it's not going to be visible on the prompt line. Anyway, the assignment you have should work in adding new commands to PROMPT_COMMAND, the semicolon works as a separator there.
    – ilkkachu
    yesterday










  • Yes, I realise now that environment variables can be a colon separated list of values or a list of commands.
    – MyWrathAcademia
    yesterday











  • @MyWrathAcademia, mmm, well. Colon-separated lists of paths are indeed common (PATH, CDPATH, LD_LIBRARY_PATH, ... though the man page says the last one can also use semicolons as separators(!)). I don't think ones that take commands are that common, but then you have lots and lots of envvars that are really just single values (LANG and all the LC_*, USER, EDITOR...) or single paths (HOME, MAIL...). The wonderful thing is that they can be whatever the command that uses them wants them to be...
    – ilkkachu
    yesterday















Thanks for showing how to test for it, it's very useful, but how do I use PROMPT_COMMAND without overwritting the value that is already set or does it not overwrite since it is not a colon separated list?
– MyWrathAcademia
yesterday





Thanks for showing how to test for it, it's very useful, but how do I use PROMPT_COMMAND without overwritting the value that is already set or does it not overwrite since it is not a colon separated list?
– MyWrathAcademia
yesterday













To touch on your last paragraph, that is the default PROMPT_COMMAND on my fedora system. I have not modified it in any way.
– MyWrathAcademia
yesterday





To touch on your last paragraph, that is the default PROMPT_COMMAND on my fedora system. I have not modified it in any way.
– MyWrathAcademia
yesterday













@MyWrathAcademia, oh, sorry, that's the escape sequence for setting the window title. That makes more sense; it's not going to be visible on the prompt line. Anyway, the assignment you have should work in adding new commands to PROMPT_COMMAND, the semicolon works as a separator there.
– ilkkachu
yesterday




@MyWrathAcademia, oh, sorry, that's the escape sequence for setting the window title. That makes more sense; it's not going to be visible on the prompt line. Anyway, the assignment you have should work in adding new commands to PROMPT_COMMAND, the semicolon works as a separator there.
– ilkkachu
yesterday












Yes, I realise now that environment variables can be a colon separated list of values or a list of commands.
– MyWrathAcademia
yesterday





Yes, I realise now that environment variables can be a colon separated list of values or a list of commands.
– MyWrathAcademia
yesterday













@MyWrathAcademia, mmm, well. Colon-separated lists of paths are indeed common (PATH, CDPATH, LD_LIBRARY_PATH, ... though the man page says the last one can also use semicolons as separators(!)). I don't think ones that take commands are that common, but then you have lots and lots of envvars that are really just single values (LANG and all the LC_*, USER, EDITOR...) or single paths (HOME, MAIL...). The wonderful thing is that they can be whatever the command that uses them wants them to be...
– ilkkachu
yesterday




@MyWrathAcademia, mmm, well. Colon-separated lists of paths are indeed common (PATH, CDPATH, LD_LIBRARY_PATH, ... though the man page says the last one can also use semicolons as separators(!)). I don't think ones that take commands are that common, but then you have lots and lots of envvars that are really just single values (LANG and all the LC_*, USER, EDITOR...) or single paths (HOME, MAIL...). The wonderful thing is that they can be whatever the command that uses them wants them to be...
– ilkkachu
yesterday












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460651%2fis-prompt-command-a-colon-separated-list%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)