Linux/Unix – Handling your System Shell

Customizing Your Shell 

The following sections describe the most common ways to customize the shell−−including changing the text of the shell prompt and creating aliases for other commands. These customizations will apply to the rest of your current shell session, unless you change them again. Eventually, you will want to make them work all the time, like whenever you log in or start a new shell−−and how to do this is discussed below.

 

Changing the Shell Prompt

A shell variable is a symbol that stores a text string, and is referenced by a unique name. bash keeps one special variable, named PS1, for the text of the shell prompt. To change the text of the shell prompt, you need to change the contents of the PS1 variable. To change a variable’s contents, type its name followed by an equal sign (`=’) character and the string that should replace the variable’s existing contents. To change your shell prompt to `Your wish is my command: ‘, type:

 

$ PS1=’Your wish is my command: ‘

Your wish is my command:

Since the replacement text has spaces in it, we’ve quoted it. You can put special characters in the prompt variable in order to output special text. For example, the characters `\w’ in the value of PS1 will list the current working directory at that place in the shell prompt text.

To change your prompt to the default bash prompt−−the current working directory followed by a `$’ character−−type:

$ PS1=’\w $ ‘

~ $

 

The following table lists some special characters and their text output at the shell prompt.

SPECIAL CHARACTER

TEXT OUTPUT

\a

Inserts a C−g character, which makes the internal speaker beep. (It “rings the system bell”; C−g is sometimes called the bell character.)

\d

The current date.

\h

The hostname of the system.

\n

A newline character.

\t

The current system time, in 24−hour format.

\@

The current system time, in 12−hour a.m./p.m. format.

\w

The current working directory.

\u

Your username.

\!

The history number of this command.

 

You can combine any number of these special characters with regular characters when creating a value for PS1.

 

To change the prompt to the current date followed by a space character, the hostname of the system in parenthesis, and a greater−than character, type:

$ PS1=’\d (\h)62;’

28 Oct 2008 (mgsotoso)62;

Advertisements

About msotela

This blog is for anyone who wants to access the power of a Linux system as a systems administrator or user. You may be a Linux enthusiast, a Linux professional, or possibly a computer professional who is increasingly finding the Windows systems in your data center supplanted by Linux boxes.

Posted on March 15, 2009, in Unix/Linux. Bookmark the permalink. Leave a comment.

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: