The "$" is not part of the shell-command , thats the prompt symbol in "Terminal" app (which is a shell-management app) , this symbol is used in guides / instructions / manuals etc , to indicate a user : run the command in a general shell.
Its similar to windows-command-line prompt, which has the ">" symbol as prompt indicator.
In unix/macOS/linux the "$" before a shell-command is indicating, you run the shell-command in a general shell/Terminal window initiated by your own user account , and if root access is needed temporarily, then use "sudo" in front of a specific command.
In unix/macOS/linux the "#" before a shell-command is indicating, you run the shell-command in a privileged shell/Terminal window initiated by privileged user "root" , so using "sudo" is not needed.
So do not use the 1st symbol "$" or "#" itself , when use/run a shell-command inside the Terminal app.
if a shell-command has the comment seciton after the shell-command in same line,
then dont use the # symbol in a shell-command, & remove the # symbol & remove all words after the hash symbol in that same line, before using the shell-command in Terminal app.
be-careful, sometime "#" symbol can be par of command, then keep it intact.
By the way , to setup configuration/settings related lines (also knows as config-command-line or config-command) in config/settings related ( *.cfg , *.ini etc ) files,
you will have to open the config file by using a text Editor software / tool , such as "nano", "vi", "gEdit", "TextMate", etc, and after copy-pasting config-lines, etc you will have to "Save" your new code/changes inside the text Editor software/tool, & then exit from editor.
When you copy config-commands displayed in a guide , & paste into the text editor,
you will/may see some config-command or some config-line has the "#" symbol as 1st symbol of a line,
then that symbol indicates, that specific line is a comment-line, & not a config-command line,
these lines explain whats doing what, etc.
In config line, the "#" symbol must be kept-intact if its the 1st symbol of a line, & some time the "#" will be used in end a config-command, to start a comment-section in same line, then the "#" symbol must remain where its used/placed.
Such comment/explanation line or comment/explanation section/portion at end of a config-command line , must start with the "#" symbol , inside a config file.
( there are other symbols for creating "comment" section/portion/line , but the # is just too popular & has become a convention for config files. )