7

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.

5

1 Answer 1

8

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

enter image description here

Since, in Bash,

  1. 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

  1. 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
2
  • From the link it's clear that 36 means Cyan, but what does [\033 mean?
    – athos
    Commented Dec 22, 2022 at 23:24
  • 1
    @athos As I've mentioned in the above explanation, in Bash, non-printing escape sequences have to be enclosed in [\033[ and ]. For more info click here and here. Commented Jan 1, 2023 at 21:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.