20

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?

1 Answers1

37

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.

Stephen Kitt
  • 434,908
Kusalananda
  • 333,661
  • 2
    Also in 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
  • 1
    Also note that 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
  • 2
    a very important choice of # for root is that if you copy a command including it you will not cause damages (as # starts a comment, so will comment your command (well, its first line)). Some people use ">" and if you copy it as well, it can clobber (empty completely) binaries if the command has a full or relative path or if you are in the right directory (and have sufficient rights, for example if you are root). I have seen this happen. – Olivier Dulac May 03 '17 at 09:14
  • 1
    @StéphaneChazelas: Didn't the #-for-root convention originate a long time before terminals where cutting-and-pasting an entire line is easily possible became common? – hmakholm left over Monica May 03 '17 at 11:59
  • 1
    @HenningMakholm, yes. It originated even before csh introduced # as a comment leader. Still, it's true that #... 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
  • It would be more correct to say Bourne-like than 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
  • It looks like 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
  • IIRC, in early Unices, @ 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