Ask HN: Why dollar sign for shell commands?

  • > Many docs use a dollar sign `$` to indicate a shell command.

    Given that the default unix shell prompt has traditionally been a dollar sign, this use in documentation is likely just a result of attempting to make the docs more closely resemble an actual interactive session view.

    > What is your own ideology on using dollar signs in front of shell commands?

    Most authors will wish to, in some way, highlight actual commands separately from the surrounding prose. If in a limited typesetting environment (i.e., plain text) then use of $ to prefix commands is one of the very few ways to do so. If in an environment with more highlighting ability (i.e., HTML document) then the author is free to choose a highlight convention that works for their document.

    > What are best practices for providing shell commands in docs?

    It is probably best to provide some for of "highlight" to indicate the shell commands separately from the prose. What form that "highlight" takes is determined by what formatting is available for the documentation being created.

    In any case, the author should be consistent in their usage of the highlight, and it is often good to include, up front, a brief description of the meaning of the highlight so the reader is not left guessing what "bold face, indent" vs "underline, flush" might respectively mean.

  • Also, $ clarifies that the line is indeed a shell command.

    That's all there is to it. Move on. Worry about something else.

  • I have not got as far as coming up with an "ideology" about this. I include the $ to indicate a shell command, a convention I think most books and manuals follow. I don't find that makes copy/paste harder, at least not enough to matter.

    On the scale of things I care about this ranks pretty close to the bottom.

  • Bash’s default prompt ends with a $ when it’s not running as root.

  • Why indeed, when cool people use a lambda.