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?dischoen– dischoen2013-12-18 15:17:54 +00:00Commented Dec 18, 2013 at 15:17
Add a comment |
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.amon– amon2013-11-24 10:25:20 +00:00Commented Nov 24, 2013 at 10:25 - 4@amon cmd.exe can barely be considered as a shelltoasted_flakes– toasted_flakes2013-11-24 10:46:47 +00:00Commented 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– amon2013-11-24 11:01:37 +00:00Commented Nov 24, 2013 at 11:01 - 2In instructions that occasionally require root, it's common to see
$and#used to indicate which operations require escalation.Lars Viklund– Lars Viklund2013-12-18 17:14:39 +00:00Commented Dec 18, 2013 at 17:14