I recently discovered that the # sign indicates that you're root on the shell (at least in a bash shell), and the $ sign indicates that you're not.
What is the name of this sign and does it really have the meaning that I give to it?
Is it only a bash thing?
Example with default bash configuration on Ubuntu:
john@mycomputer /tmp $ echo "I'm a simple user" mycomputer /tmp # echo "I'm the root user"
There does not appear to be a formal definition of the prompt character indicating your privileges.
This thorough answer to “What is the origin of the UNIX $ (dollar) prompt?” provides lots of historical background, but it does not have a name for this indicator either.
In the absence of an official term, I'd call this the “prompt privilege indicator” or the “prompt indicator symbol” or even just “prompt indicator.”
All shells have a prompt whose default string ends in an indicator symbol, which (by default) almost always indicates whether you are root. Most shells allow you to change the prompt and most shells have a way to specify the prompt indicator symbol.
Here's what you can find in the various shell docs and standards:
A segment of the bash man page:
PROMPTING
When executing interactively, bash displays the primary prompt PS1 when
it is ready to read a command, and the secondary prompt PS2 when it
needs more input to complete a command. Bash displays PS0 after it
reads a command but before executing it. Bash allows these prompt
strings to be customized by inserting a number of backslash-escaped
special characters that are decoded as follows:
…
\$ if the effective UID is 0, a #, otherwise a $
From the zsh man pages:
Shell state
%# A `#' if the shell is running with privileges, a `%' if not.
Equivalent to `%(!.#.%%)'. The definition of `privileged', for
these purposes, is that either the effective user ID is zero,
or, if POSIX.1e capabilities are supported, that at least one
capability is raised in either the Effective or Inheritable
capability vectors.
The POSIX standard doesn't even specify what the privileged prompt symbol should be:
PS1
Each time an interactive shell is ready to read a command, the value of this variable shall be subjected to parameter expansion and written to standard error. The default value shall be
$. For users who have specific additional implementation-defined privileges, the default may be another, implementation-defined value.
See also the dash man page (dash is a popular basic POSIX shell, often installed as /bin/sh):
PS1 The primary prompt string, which defaults to ``$ '', unless you
are the superuser, in which case it defaults to ``# ''.
POSIX and dash don't have anything dynamic in what you can set $PS1 to. The default prompt is set once and is replaced by any assignments to the PS1 variable, losing the ability to distinguish between root and unprivileged users with a single character. You'd have to write your own code to determine if you're privileged and use its output in your PS1 assignment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With