1

Most code samples I see that demonstrate shell code preface each command with $. Having a prefix makes sense, but I'm confused as to why $ is used in particular. Some other symbol, like !, that can be copied and pasted into a prompt without affecting the command's execution makes far more sense to me. So where does this notation come from?

1

1 Answer 1

8

$ is the default prompt prefix for a non-escalated bourn or sh shell on most *nix systems. It signifies that the code exemplified should be executed using one of those associated shells. zsh and csh have % as a prefix. The fish shell uses >. Putting the prefix is simply a quick way to let the reader know what shell the command is destined for.

4
  • More often than for fish, > would be used for cmd.exe – of course this depends on the context.
    – amon
    Nov 24, 2013 at 10:25
  • 3
    @amon cmd.exe can barely be considered as a shell Nov 24, 2013 at 10:46
  • @grasGendarme ;-) – but this doesn't matter: cmd.exe is the default text shell on Windows (technically, explorer.exe is the default shell), and it does see a significant amount of use. Simple commands look the same in cmd.exe as they do in bash, but differences WRT quoting (' vs ") and escaping (backslashes, glob expressions), as well as advanced operators often make it a necessity to indicate which shell you are using.
    – amon
    Nov 24, 2013 at 11:01
  • 2
    In instructions that occasionally require root, it's common to see $ and # used to indicate which operations require escalation. Dec 18, 2013 at 17:14

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.