Operating a standard bash shell on a server, the PS1 prompt defaults đồ sộ ending in a $ for non-root users, and # for root.
IE:
ubuntu@server:~$ sudo su
root@server:/home/ubuntu#
Why is this?
asked Jun 23, năm nhâm thìn at 22:02
JacklynnJacklynn
3851 gold badge3 silver badges7 bronze badges
1
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 đồ sộ tell if you were running as superuser or not.
#
is also the comment character, so sánh anyone blindly re-entering data wouldn't lập cập any real commands.
More modern shells (eg ksh, bash) continue this distinction of $
and #
although it's less important when you can mix more complicated values such as the username, hostname, directory :-)
answered Jun 23, năm nhâm thìn at 22:16
Stephen HarrisStephen Harris
47.3k7 gold badges110 silver badges132 bronze badges
4
Tradition.
The POSIX standard says (my emphasis):
PS1
This variable is used for interactive prompts. Historically, the "superuser" has had a prompt of
#
. Since privileges are not required to be monolithic, it is difficult đồ sộ define which privileges should cause the alternate prompt. However, a sufficiently powerful user should be reminded of that power by having an alternate prompt.
See also this answer đồ sộ virtually the same question on the SuperUser diễn đàn.
answered Jun 23, năm nhâm thìn at 22:19
Kusalananda♦Kusalananda
345k39 gold badges709 silver badges1k bronze badges
You must log in đồ sộ answer this question.
Not the answer you're looking for? Browse other questions tagged
.
Not the answer you're looking for? Browse other questions tagged
.