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?
-
1You can have a look here on SuperUser: What is the origin of the UNIX $ (dollar) prompt?– dischoenDec 18, 2013 at 15:17
1 Answer
$
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.
-
More often than for fish,
>
would be used for cmd.exe – of course this depends on the context.– amonNov 24, 2013 at 10:25 -
3
-
@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.– amonNov 24, 2013 at 11:01 -
2In instructions that occasionally require root, it's common to see
$
and#
used to indicate which operations require escalation. Dec 18, 2013 at 17:14