21

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?

4
  • 2
    export PS1=% ?? Commented May 3, 2017 at 13:51
  • @RomanGräf, what's that? Commented May 3, 2017 at 13:58
  • 1
    You can change the normal $ sign using export PS1=... where ... is the replacement. Commented May 3, 2017 at 13:59
  • @Roman Gräf: You can actually do a whole lot more with the prompt than just change the character. Mine includes the machine name (since I often have xterm windows into other machines) and the last few directories in the current path. And if I'm root, it becomes bright red. Commented May 4, 2017 at 5:29

1 Answer 1

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.

8
  • 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. Commented May 3, 2017 at 7: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). Commented May 3, 2017 at 7: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. Commented May 3, 2017 at 9: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? Commented May 3, 2017 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. Commented May 3, 2017 at 12:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.