Skip to main content
2 of 2
added 237 characters in body
ilkkachu
  • 148k
  • 16
  • 268
  • 441

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.

ilkkachu
  • 148k
  • 16
  • 268
  • 441