15

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?

  • 2
    export PS1=% ?? – Roman Gräf May 3 '17 at 13:51
  • @RomanGräf, what's that? – Max Koretskyi aka Wizard May 3 '17 at 13:58
  • 1
    You can change the normal $ sign using export PS1=... where ... is the replacement. – Roman Gräf May 3 '17 at 13:59
  • @RomanGräf, I see, thanks for the suggestion – Max Koretskyi aka Wizard May 3 '17 at 14:17
  • @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. – jamesqf May 4 '17 at 5:29
28

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 while sh-shells (like bash and ksh93) ordinarily uses 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 are 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) happens to coincide with the common shell comment character. Copying and pasting a command as root would render the pasted command inoperable, if the shell prompt was also copied. 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 uses 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.

  • 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 3 '17 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). – Stéphane Chazelas May 3 '17 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. – Olivier Dulac May 3 '17 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? – Henning Makholm May 3 '17 at 11:59
  • @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 3 '17 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.