Is $PROMPT_COMMAND a colon separated list?

Clash 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:
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?
bash shell command-history
add a comment |Â
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:
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?
bash shell command-history
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
add a comment |Â
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:
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?
bash shell command-history
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:
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?
bash shell command-history
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
add a comment |Â
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
add a comment |Â
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.
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 toPROMPT_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 (LANGand all theLC_*,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
add a comment |Â
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.
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 toPROMPT_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 (LANGand all theLC_*,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
add a comment |Â
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.
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 toPROMPT_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 (LANGand all theLC_*,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
add a comment |Â
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.
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.
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 toPROMPT_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 (LANGand all theLC_*,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
add a comment |Â
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 toPROMPT_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 (LANGand all theLC_*,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
add a comment |Â
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
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
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
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
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
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