Shell – Why $ is the Default User Shell Symbol and # for Root

historypromptshell

Operating a standard bash shell on a server, the PS1 prompt defaults to ending in a $ for non-root users, and # for root.

IE:

ubuntu@server:~$ sudo su
root@server:/home/ubuntu#

Why is this?

Best Answer

Historically the original /bin/sh Bourne shell would use $ as the normal prompt and # for the root user prompt (and csh would use %). This made it pretty easy to tell if you were running as superuser or not.

# is also the comment character, so anyone blindly re-entering data wouldn't run any real commands.

More modern shells (eg ksh, bash) continue this distinction of $ and # although it's less important when you can set more complicated values such as the username, hostname, directory :-)

Related Question