Monday, May 16, 2011

Changing the prompt in Shell

For changing the prompt in shell

we need to export the PS1 variable

Its by default set to \$ and # for root

To change it  simply follow the below step:

you can change to many special characters.but commonly used are:

\$     -  shows the user prompt($) or root prompt(#) ,depending on which user you are.

\W   -  shows the current working directory base name.if the current working directory is "/home/karthik/perl" then it simply appears as "perl"

\w   -  Displays the full path of the current working directory.

\t    -   prints the current time in hours.minutes and seconds(for ex:9:30:40)

\s   - prints the current shell name.For bash shell it simply prints bash as prompt.

\u - in this case it prints the current username.

These options can also be used together.

For ex:
export PS1="\t \w \$"
makes the prompt as
[18:30:40 /home/karthik]$>

export PS1="\W"
makes the prompt as  if the full path is "/home/karthik/perl"
perl>

No comments:

Post a Comment