I agree with the tenet "keep text copy+pasteable", but I think there are cases where a $
or #
can be actually justified for readability reasons.
I like to put $
or #
in front of commands when I have a block of text that mentions a command / series of commands together with its intended output. Example:
If you remove the "r" permission from a directory, you will not be able to list its contents:
$ chmod -r /tmp/test.d
$ ls /tmpotmp/test.d
ls: Permission denied
In this case, the $
marks the commands that a user would enter at the terminal prompt (I would have used #
for root terminal), and the un-prefixed lines are the command output.
I agree this can be formatted in a different way to keep it copy+pasteable, but I find this formatting more natural as it mirrors what would actually be seen on the terminal screen.