Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to display current path in sh prompt (not bash shell), which currently just shows "#", I tried with introducing this

env PS1="$(whoami)@$(hostname):$(pwd)"


set PS1="$(whoami)@$(hostname):$(pwd)"

in /etc/profile.

But as obvious this does not refresh when the the directory is changed or user changes. Please suggest a way to make this dynamic.

share|improve this question
Note that each $() runs a separate program; it would be faster to use environment variables, such as $LOGNAME, $HOSTNAME and $PWD instead. –  grawity May 29 '13 at 12:00

2 Answers 2

up vote 7 down vote accepted

Command substitutions in double quotes " get expanded immediately. That is not what you want for your prompt. Single quotes ' will preserve the substitutions in $PS1 which then get only expanded when displaying the prompt. Hence this should work:

export PS1='$(whoami)@$(hostname):$(pwd)'

If you want the usual dollar sign and a space at the end of your prompt, simply add $ at the end (no escaping necessary): export PS1='$(whoami)@$(hostname):$(pwd)$ '

share|improve this answer
Worked like a charm after changing 'set' to 'export' in your answer export PS1='$(whoami)@$(hostname):$(pwd)$' I saved the change s to /etc/profile. Thank you. –  Bleamer May 29 '13 at 10:22
@Bleamer: set worked for me (but I didn't had a native sh). But I'll change it to export to comply with your setup. –  mpy May 29 '13 at 11:01
Is there any way to make this permanent? Currently I have to do it each time I log in. Thanks! –  the.ufon Sep 2 at 7:07
You have put this line to /etc/profile (see question) or ~/.profile?! –  mpy Sep 2 at 16:39
sh-4.2$ export PS1="\u@\h:\w>"
jenny@serenity:~>cd /usr/local
share|improve this answer
I am afraid that works for bash shell not for sh, when i do this I get \u@\h:\w> as my command prompt –  Bleamer May 29 '13 at 10:11
Must be a different sh version; as you can see from the first line, it worked for me in sh 4.2. –  Jenny D May 29 '13 at 10:12
That may be the case. This shell is from Busy Box. Thank you. Appreciate your help though. –  Bleamer May 29 '13 at 10:25
@Bleamer, it works for me with BusyBox v1.19.4 built-in shell (ash). –  cjm Sep 11 '13 at 4:26
Thank you for response @cjm, though I'll avoid digging further into this. –  Bleamer Sep 27 '13 at 9:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.