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

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,

  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

Leave a Comment