Show subshell levels in bash prompt

For bash and tcsh, an environment variable SHLVL contains the sub-shell level. Login shells are top-level shells.

Lets say we want our shell to show the following prompt:

[user_name@host_node current_directory]$ …top level shells

For others:

[(subshell_number)user_name@host_node current_directory]$

In bash, login shells read the .bash_profile, while all sub-shells read the .bashrc

So the following changes should be made:

PS1='[\u@\h \W]$ ‘ … for .bash_profile

PS1='[($SHLVL)\u@\h \W]$ ‘ … for .bashrc

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: