Ubuntu: Why do people prefix code examples with dollar sign? [duplicate]



Question:

This question already has an answer here:

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)


Solution:1

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.


Solution:2

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".


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »