D
D
Drovosek012021-03-18 10:22:50
bash
Drovosek01, 2021-03-18 10:22:50

Why do most bash script examples start with a $ sign?

On the Internet, in different guides, very often, when they give an example of entering several commands in the terminal, then at the beginning of each line of the code example, for use in the terminal, they put "$ ".

I don't understand why they do it? Indeed, in this case, you will have to manually select the entire line without these characters. If they weren't there, it would be possible to click LMB on the line 3 times and then Ctrl + C and already use the code.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Karbivnichy, 2021-03-18
@Drovosek01

The "$" sign means that the command will be executed on behalf of an unprivileged user, i.e. not from root.
The "#" sign indicates that the command must be run as the root user.

V
Valdemar Smorman, 2021-03-18
@smorman

User Mode:
[email protected]_nework_pc_mame:-$- where user is your username in the system and when you work from under it, it is displayed $
If you type:
sudo -i- then you get into Superuser Mode: - you switched to Superuser mode and therefore it is displayed ?! Or different kinds of teams?!
[email protected]:-##

Команды работают от местоположения курсора:
Удалить слово вперед          Ctrl+D
Удалить слово назад	      Ctrl+W
Удалить до конца строки     Ctrl+K
Удалить до начала строки   Ctrl+U
Вставить удаленное             Ctrl+Y

And if you run the command in the Terminal: - you will see a lot of useful things ...
bind -p | grep -v 'self\|not bound\|do-'
Very useful commands for working with text in the Terminal
"\C-g": abort
"\C-x\C-g": abort
"\e\C-g": abort
"\C-j": accept-line
"\C-m": accept-line
"\C-b": backward-char
"\eOD": backward-char
"\e[D": backward-char
"\C-h": backward-delete-char
"\C-?": backward-delete-char
"\C-x\C-?": backward-kill-line
"\e\C-h": backward-kill-word
"\e\C-?": backward-kill-word
"\e\e[D": backward-word
"\e[1;3D": backward-word
"\e[1;5D": backward-word
"\e[5D": backward-word
"\eb": backward-word
"\e<": beginning-of-history
"\C-a": beginning-of-line
"\eOH": beginning-of-line
"\e[1~": beginning-of-line
"\e[H": beginning-of-line
"\e[200~": bracketed-paste-begin
"\C-xe": call-last-kbd-macro
"\ec": capitalize-word
"\C-]": character-search
"\e\C-]": character-search-backward
"\C-l": clear-screen
"\C-i": complete
"\e\e": complete
"\e!": complete-command
"\e/": complete-filename
"\[email protected]": complete-hostname
"\e{": complete-into-braces
"\e~": complete-username
"\e$": complete-variable
"\C-d": delete-char
"\e[3~": delete-char
"\e\\": delete-horizontal-space
"\e-": digit-argument
"\e0": digit-argument
"\e1": digit-argument
"\e2": digit-argument
"\e3": digit-argument
"\e4": digit-argument
"\e5": digit-argument
"\e6": digit-argument
"\e7": digit-argument
"\e8": digit-argument
"\e9": digit-argument
"\C-x\C-v": display-shell-version
"\el": downcase-word
"\e\C-i": dynamic-complete-history
"\C-x\C-e": edit-and-execute-command
"\C-x)": end-kbd-macro
"\e>": end-of-history
"\C-e": end-of-line
"\eOF": end-of-line
"\e[4~": end-of-line
"\e[F": end-of-line
"\C-x\C-x": exchange-point-and-mark
"\C-f": forward-char
"\eOC": forward-char
"\e[C": forward-char
"\C-s": forward-search-history
"\e\e[C": forward-word
"\e[1;3C": forward-word
"\e[1;5C": forward-word
"\e[5C": forward-word
"\ef": forward-word
"\eg": glob-complete-word
"\C-x*": glob-expand-word
"\C-xg": glob-list-expansions
"\e^": history-expand-line
"\e#": insert-comment
"\e*": insert-completions
"\e.": insert-last-argument
"\e_": insert-last-argument
"\C-k": kill-line
"\e[3;5~": kill-word
"\ed": kill-word
"\C-n": next-history
"\eOB": next-history
"\e[B": next-history
"\en": non-incremental-forward-search-history
"\ep": non-incremental-reverse-search-history
"\C-o": operate-and-get-next
"\C-x!": possible-command-completions
"\e=": possible-completions
"\e?": possible-completions
"\C-x/": possible-filename-completions
"\[email protected]": possible-hostname-completions
"\C-x~": possible-username-completions
"\C-x$": possible-variable-completions
"\C-p": previous-history
"\eOA": previous-history
"\e[A": previous-history
"\C-q": quoted-insert
"\C-v": quoted-insert
"\e[2~": quoted-insert
"\C-x\C-r": re-read-init-file
"\C-r": reverse-search-history
"\e\C-r": revert-line
"\er": revert-line
"\[email protected]": set-mark
"\e ": set-mark
"\e\C-e": shell-expand-line
"\C-x(": start-kbd-macro
"\e&": tilde-expand
"\C-t": transpose-chars
"\et": transpose-words
"\C-x\C-u": undo
"\C-_": undo
"\C-u": unix-line-discard
"\C-w": unix-word-rubout
"\eu": upcase-word
"\C-y": yank
"\e.": yank-last-arg
"\e_": yank-last-arg
"\e\C-y": yank-nth-arg
"\ey": yank-pop

S
Saboteur, 2021-03-18
@saboteur_kiev

When working on the command line, you have a Command prompt - a prompt that looks like
[email protected]:directory $
after which you write a command.
You can shorten the prompt string to $ (or # if this is a superuser)
In the examples, you can see in this way where the command to be entered is, and where is what the command displays on the screen.
Conveniently.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question