Unix shells are very powerful and versatile. This article summarizes some tips & tricks how to customize your working environment when utilizing the Unix shell Bash.
Tune your Shell Prompt
When you are interested in customizing your shell prompt you may take a look at the following articles:
To get an idea how the customization of shell prompts is working, the next example will introduce a basic use-case. Let us suppose we want to create a prompt containing your username, the hostname, your current working directory and a custom string. Then we could execute the following statement to modify your the command line prompt.
# set a custom command line prompt
$ export PS1="MyPrompt: u@h w> "
MyPrompt: mario@server ~>
MyPrompt: mario@server ~> cd /usr/bin
MyPrompt: mario@server /usr/bin>
The string assigned to PS1 did contain the following ‘macros‘:
- u – username
- h – hostname
- w – your current working directory
Please note, that ‘~’ is the synonym of your user home directory
Further tips and ‘macros‘ may be found in the previously mentioned articles.
Add Variables
There are a lot of further variables available in Unix shells. By adding ‘$variable_name’ to your shell prompt the value of the variable will be visible as part of your prompt line(s). And if the required information is not available just define your own variable.
The following article contains a list of variables available in bash shells be default:
Add Functions
Additionally you are able to define shell functions that may be called from your prompt definition each time when it is printed.
The following article contains additional hints that are required to apply advanced features to your Bash prompt:
Add Executables
By calling scripts and other executables from your prompt definition you are able to place your code required for assembling your prompt line in external files.
Add Colors
When you are utilizing a terminal window supporting ANSI color codes you are able to add colors to your prompt. The following list contains some details regarding the utilization of colors at your terminal window.
Commands to Change Colors
--------------------------
e[x;ym definition of a color code. The following text will be printed
in a new color.
e[ beginning of a color definition
x;ym end of a color definition incl. color code values
e[m reset the color to standard ones
Color codes
------------
Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown 0;33
The following simple example contains a definition of a color prompt, where just a substring of the prompt appears in a different color.

Please note that there are a number of options available to set properties of the foreground and background. Additionally there are tools available to modify terminal properties, like the command line tool 'tput'.
Add Aliases
As you already do know it is possible to define custom alises at command line. You are allowed to utilize these aliases within the string of your prompt definition. The following article contains details regarding the definition of aliases.
Incoming search terms: