6

I've been wondering about this for years, but never questioned it as far that I would ask this in public. I often come across websites that, for instance, explain the installation of a software in the command-line. What I don't get is why some keep the $-sign in their examples.

Example:

$ npm install -g some-package
$ gulp make

This, of course, makes it difficult to copy&paste the given example. Is this:

  • pure laziness, where the author copies from this own shell?
  • an intentional way to prevent copy & paste, because the author finds the read should understand what he does
  • something else (explanation please)
  • I see that as "type this command at your shell prompt". And of course laziness, but in the positive sense: c2.com/cgi/wiki?LazinessImpatienceHubris – glenn jackman Dec 23 '15 at 16:06
  • it is habit some sites don't have code formating, so you need to indicate it is in terminal - just edit it out we generally don't do that here for copy\paste ability (tripple click will include the $) meta.askubuntu.com/questions/282/… – Mateo Dec 23 '15 at 16:31
  • If you have to execute a long list of commands prefixed with $: sed 's/^$ //' <<EOF | bash, paste the list of commands, hit ENTER, type EOF, hit ENTER. To edit it for the site: sed 's/^$ //' <<EOF | xclip -sel clipboard, paste the list of commands, hit ENTER, type EOF, hit ENTER. – kos Dec 23 '15 at 22:07
10

This is not a code example. The $ at the beginning of the line indicates that it is a shell command. You can still copy and paste each line individually, as each line must be entered into the terminal individually anyway, and ignore the preceding $ and characters.

Examples which are actually shell scripts or other program code, do not start with the $ symbol, and are generally preceded by a statement that the contents are in foo.sh file.

The $ symbol is often used to denote hexadecimal values as well, when discussing lower level programming topics.

  • 2
    The $ sign also signify that the shell commands runs in normal user-mode, # denotes sudo or root rights needed for running the commands. Merry Christmas – Ken Mollerup Dec 23 '15 at 17:04
1

The $ at the beginning of a "typescript" is the simplified command prompt for an unprivileged user. For commands run in a $UID==0 (aka root) environment, example writers use the # prompt. It's much simpler than prefixing each example command with "run this a user" or "run this as root".

Not the answer you're looking for? Browse other questions tagged .