Bug #2931

PS1 prompt in default user .profile is incorrect

Added by Jim Klimov almost 9 years ago. Updated over 3 years ago.

OS/Net (Kernel and Userland)
Target version:
Start date:
Due date:
% Done:


Estimated time:


The PS1 prompt is defined incorrectly in OpenIndiana user's ~/.profile files (cloned for each new user from /etc/skel/.profile).
Currently this is defined as:

    [[ "${LOGNAME}" == "root" ]] && printf "%s" "${PWD/${HOME}/~}# " ||
    printf "%s" "${PWD/${HOME}/~}\$ ")'

The main problem is with the substitution for HOME: "as is" this eradicates a matching string from anywhere in the current directory path, i.e. "/root" disappears from the paths below:

root@openindiana:/# cd /zones/build/zone1/root/etc
root@openindiana:/zones/build/zone1~/etc# ...

root@openindiana:/# mkdir /rootpool
root@openindiana:/# cd /rootpool
root@openindiana:~pool# ...

root@openindiana:/# mkdir /root/subdir
root@openindiana:/# cd /root/subdir/
root@openindiana:~/subdir# ...

First can be fixed by prefixing HOME with the dash character (#) in the expression. Second part is problematic for me in bash alone, but I can solve it with sed like shown in the end of the post. Third "seems" to work ;)

A couple of arguable problems are:
1) The directory (substitution) is the same, but used twice (with different characters for root and user); it will be more maintainable (maybe a bit slower?) to split these components as shown below;
2) Is printf better/faster than echo in this simple case of a fixed static line?

Suggested replacement is (choice of escape character to separate parts of the regexp in sed is questionable though):

    echo ${PWD} | sed "s,^${HOME}\(\/.*\)*$,\~\1,")$(
    [[ "${LOGNAME}" == "root" ]] && echo "# " || echo "$ " )'

At least, all the examples above work correctly with this definition.


Updated by Yuri Pankov almost 9 years ago

Why not use something simple (bash is default shell anyway):

PS1="\u@\h:\w\\$ " 


Updated by Jim Klimov almost 9 years ago

That does make sense and this or similar definition was used in .bash_profile for ages.
IMHO, the .profile shared by different shell implementations should use the "minimal common syntax" as to work in all shells. For example, the bash-builtins are bound to be faster than calling external programs every time - so an override in user's or default bash_profile is encouraged (perhaps as part of this or another bug? - add equivalent default profiles optimized for specific shells)


Updated by Ken Mays about 8 years ago

  • Assignee set to OI illumos

Updated by Electric Monk over 4 years ago

git commit 719d176126cc1c689a469d4c3553d770d1c4e94e

commit  719d176126cc1c689a469d4c3553d770d1c4e94e
Author: Toomas Soome <>
Date:   2016-12-02T14:53:39.000Z

    6723 etc/skel needs cleanup
    2931 PS1 prompt in default user .profile is incorrect
    Reviewed by: Andrew Stormont <>
    Reviewed by: Lauri Tirkkonen <>
    Reviewed by: Gordon Ross <>
    Reviewed by: Adam Števko <>
    Reviewed by: Alexander Pyhalov <>
    Approved by: Hans Rosenfeld <>


Updated by Aurélien Larcher over 3 years ago

  • Category set to OS/Net (Kernel and Userland)
  • Status changed from New to Resolved
  • Target version set to Hipster
  • % Done changed from 0 to 100
  • Tags changed from needs-triage to illumos

Resolved by referenced illumos ticket.

Also available in: Atom PDF