Skip to content
Home » Solaris » How Solaris Customize Prompt PS1

How Solaris Customize Prompt PS1

Customize Prompt PS1

For a newly created user in Solaris, its console prompt (PS1) looks a little different from Linux prompt, especially when the path of present working directory (PWD) is long.

oracle@test:~$ cd $ORACLE_HOME
oracle@test:/u01/app/oracle/product/19.0.0/dbhome_1$

As you can see, it puts the absolute path in prompt. In my opinion, it's totally unnecessary to list the full path.

In this post, we'll talk about how to modify the console prompt (PS1) and go back to Linux's style. The file we should modified is ~/.profile.

Solution

Let's see current PS1.

oracle@test:/u01/app/oracle/product/19.0.0/dbhome_1$ cd -
/export/home/oracle
oracle@test:~$ vi ~/.profile
...
case ${SHELL} in
*bash)
    typeset +x PS1="\u@\h:\w\\$ "
    ;;
esac

We changed the format of PS1 into this:

case ${SHELL} in
*bash)
    typeset +x PS1="[\u@\h \W]\\$ "
    ;;
esac

What we changed above are:

  • A left square bracket is prefixed to PS1.
  • A right square bracket is inserted before the dollar sign.
  • The semicolon used to separate hostname and directory is replaced with a white space.
  • The prompt variable \w is replaced with a uppercase \W for displaying only the basename instead of full directory.

To take it effect immediately, we source the file by a dot command.

oracle@test:~$ . ~/.profile
[oracle@test ~]$

The prompt style now goes back to Linux's.

For more customization options, you may check prompt variables for controlling the prompt.

Leave a Reply

Your email address will not be published. Required fields are marked *