While watching a video, I saw the following:
% more tinyUF.txt
10
4 3
3 8
6 5
What is this %
sign before more
command?
While watching a video, I saw the following:
% more tinyUF.txt
10
4 3
3 8
6 5
What is this %
sign before more
command?
That's the shell prompt, or more precisely, it's the shell's primary prompt (there are several). It's the shell's way of saying, "go ahead, I'm ready for input now".
The %
prompt is common in csh
-type shells and in the zsh
shell, while sh
-shells (like bash
and ksh93
) ordinarily use a $
as the prompt.
The prompt usually changes to #
for the root user since a sufficiently powerful user should be reminded of that power by having an alternate prompt (as the POSIX standard puts it).
The primary prompt in sh
-type shells is determined by the value of the shell variable PS1
.
Summary of the comments below, with additions:
The #
character of the root prompt (used by both sh
and csh
shells) coincides with the familiar shell comment character. Copying and pasting a command as root would render the pasted command inoperable if a user also copied the shell prompt. Note that #
was adopted as the root prompt before the shell had a comment convention (reference: email from Doug McIlroy).
The es
and rc
shells of Plan 9 use the ;
character as the default prompt. A consequence of this is that copying and pasting a command, including the prompt, will still mean that the pasted command is valid (and it will be executed).
A way for enabling one to have a custom, but still copy-pastable, shell prompt would be to use : something ;
, where something
could be the current directory, hostname or time, for example.
zsh
(a Bourne-style shell, but with lots of features from tcsh
). Note that Bourne-like and csh-like shells typically use #
for users of uid 0.
– Stéphane Chazelas
May 03 '17 at 07:22
rc
-like shells use ;
there (one can copy-paste the full line and that's valid shell code, same idea as root's #
prompt being a comment).
– Stéphane Chazelas
May 03 '17 at 07:25
#...
lines are comments when copy-pasted even if it was not the intention. I don't know if it was the intention behind ;
in rc
either, though I observe it's a convenient consequence.
– Stéphane Chazelas
May 03 '17 at 12:31
sh
-type. The Thomson shell (sh
until Unix v6 before it was replaced by the Bourne shell in v7) had %
/#
as well. I do not know why the Bourne shell changed it to $
. Possibly to make it clear to the user that they were getting a different shell from what they would be used to before. Note that #
as a comment leader was introduced by csh. The Bourne shell had no comments until much later (you'd use the :
null-command as an ersatz).
– Stéphane Chazelas
May 03 '17 at 20:46
sh
in PDP-7 Unix and Unix V1 had @
/#
before it was changed to %
/#
(v5 had %
, but I didn't find what it was for v2, v3, v4).
– Stéphane Chazelas
May 03 '17 at 21:59
@
was also the kill
character (now ^U) and #
was erase (now ^H or ^?), so if the early ttys had had the capability to copy-paste, that would have caused interesting behaviours
– Stéphane Chazelas
May 03 '17 at 22:03
export PS1=%
?? – Linnea Gräf May 03 '17 at 13:51$
sign usingexport PS1=...
where...
is the replacement. – Linnea Gräf May 03 '17 at 13:59