I'm trying to modify my bash terminal's appearance, and I've stumbled upon this site: http://osxdaily.com/2013/02/05/improve-terminal-appearance-mac-os-x/. However I want to try to understand the code first before implementing all the changes and I'm currently having trouble understanding this part. So it'll be really nice if someone could explain it to me thoroughly.
-
4ANSI escape codes.– DevSolarCommented Jul 5, 2019 at 2:11
-
3"Please explain this code" questions are by nature considered too broad to be on-topic here, unless they describe a single, specific, narrow aspect of the code that isn't understood, explaining as specifically as possible which parts you do and don't already know, and what research you've already done towards that end.– Charles DuffyCommented Jul 5, 2019 at 2:13
-
3See How to deal with questions of the type "I don't understand how this code works" on Meta Stack Overflow.– Charles DuffyCommented Jul 5, 2019 at 2:14
-
1This will also help understand the special chars used other than escape sequences: gnu.org/savannah-checkouts/gnu/bash/manual/…– Diego Torres MilanoCommented Jul 5, 2019 at 4:42
-
1PS1 explained: linuxnix.com/linuxunix-shell-ps1-prompt-explained-in-detail– gmargariCommented Jul 5, 2019 at 6:19
1 Answer
export
is used to set environment variable in operating system. This variable will be available to all child processes created by current Bash process ever after.
PS1
is the primary prompt which is displayed before each command, thus it is the one most people customize. read more: https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Prompts
And the statement:
\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$
dictates how the prompt is going to look like i.e
Since, in Bash,
- Non-printing escape sequences have to be enclosed in [\033[ and ]. For colour escape sequences, they should also be followed by a lowercase m.
For more about ANSI Escape Codes: https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
- There are several special characters which can appear in the prompt variables PS0, PS1, PS2 and PS4 which can be seen here: https://www.gnu.org/software/bash/manual/html_node/Controlling-the-Prompt.html
Hence:
- [\033[36m] = Cyan
- \u = Username of the current user
- [\033[m] = Reset all styles and colors
- @ = '@' character
- [\033[32m] = Green
- \h = The hostname
- : = ':' character
- [\033[33;1m] = Yellow(bold)
- \w = The current working directory, with $HOME abbreviated with a tilde(~)
- $ = Show '#' if the user ID of a user is 0, otherwise show '$' character