Tille - I can see you, read those man pages!   Tille's Site

Change the prompt according to your mood

Can you set the prompt to a certain value using a script and a case statement?

This is not possible, since the PS1 value has to be passed to the parent, and this would involve somewhat more advanced shell programming skills.

For now, however, the problem can be solved sourcing the script in stead of letting the shell execute it. It does not have to be executable in that case, just like ~/.bashrc or /etc/profile, which are both read by the shell and not executed (they are not executable either).

So, this is mood.rc:

case "$1" in
    PS1="\u@\h \w> "
    PS1="What is it?! "
    PS1="\a[\d \W]> "
    echo "Use "$0" with fine or bofh as options"

Since your shell has already been started, you do not need to include the first line of


or some comparable line.

Now source this file: (with the "." (dot) command) and one of the arguments defined in the case statement:

student9> . mood.rc bofh
What is it?! 
© 1995-2010 Machtelt Garrels - tille - Powered by vIm - Best viewed with your eyes - Validated by W3C - Last update 20100511