43
15
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)"
and
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.
One answer was to use single quotes instead of double quotes, however, that's quite the full correct answer. What you really want to do is defer evaluation of the code inside your prompt until the prompt is used. – MaasSql – 2014-10-27T14:40:44.640
All you need is to use export "PS1="$(whoami)@$(hostname):$(pwd) >" then edit /etc/profile and append this line at the end. – SDsolar – 2017-03-29T19:25:25.417
1Note that each
$()
runs a separate program; it would be faster to use environment variables, such as$LOGNAME
,$HOSTNAME
and$PWD
instead. – user1686 – 2013-05-29T12:00:58.560