digitalguy99
digitalguy99

Reputation: 549

What does export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ " mean in MacOS' bash Terminal?

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.

Upvotes: 7

Views: 7398

Answers (1)

digitalguy99
digitalguy99

Reputation: 549

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

Upvotes: 8

Related Questions