Does anyone know any way of making bash prompt extended with conditional content?
Example:
export PS1="[[ ${USER} = 'root' ]] && echo '#' || echo '\$'" # This won't work - prompt is not executed
# export PS1="\$" # This is an existing but also working equivalent
I would like to use more complex conditionals than in the given example.
I am afraid that the answers given are not correct. There is a major difference between
conditional content in the prompt
and
conditional logic in the script that sets that prompt
The answer given by Corona688 seems to be the only one related.
I agree with earlier posts that suggest setting the prompt either in your profile, or the system profile, as being the smart way of doing it, but wanted to point out that it can be done this way.
What results in printing line like:
script.sh:123 + command_executed
And modified terminal window every time an error is thrown. Before I achieved similar result with trap on ERR.