Results 1 to 6 of 6

Thread: Customizing a bash shell prompt (PS1)

Hybrid View

  1. #1

    Question Customizing a bash shell prompt (PS1)

    Hi there
    I changed the default SUSE prompt setting by modifying the shell variable PS1 to display the following information:

    \u : the username of the current user
    \h : the hostname up to the first '.'
    \w : the current working directory, with $HOME abbreviated with a tilde

    I used export command to setup a new shell prompt:

    export PS1="[\u@\h: \w]\$ "

    To add colors to the shell prompt and make a regular user prompt blue I used the following command syntax:

    export PS1="\e[0;34m[\u@\h: \w]\$ \e[m "

    Where,
    \e[ Start color scheme
    x;y Color pair to use (x;y)
    $PS1 is your shell prompt
    \e[m Stop color scheme

    List of Color code
    Color Code
    Black 0;30
    Blue 0;34
    Green 0;32
    Cyan 0;36
    Red 0;31
    Purple 0;35
    Brown 0;33
    Blue 0;34
    Green 0;32
    Cyan 0;36
    Red 0;31
    Purple 0;35
    Brown 0;33
    Replace digit 0 with 1 to get light color version.

    Finally to make the prompt setting permanent I added above export command to my .bashrc file.

    Id like to do the same for root. In Slackware or Debian in order to modify PS1 you need to edit roots .bashrc config file that is located here, /root/.bashrc. Unfortunately there isnt such file in SUSE. So when I su to became the super user I get the default prompt.

    Any ideas how to setup a custom root prompt?

    If someone is interested look here:

    BASH Shell change the color of my shell prompt under Linux or UNIX
    Bash Prompt HOWTO
    Adding Color and Customize the Bash Prompt (PS1)

  2. #2
    Join Date
    Nov 2009
    Location
    Uruguay
    Posts
    737

    Default Re: Customizing a bash shell prompt (PS1)

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    for root you must read and modify /etc/bash.bashrc

    - --
    VampirD

    Microsoft Windows is like air conditioning
    Stops working when you open a window.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.15 (GNU/Linux)
    Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

    iEYEARECAAYFAkxQej4ACgkQJQ+0ABWtaVmbXACfRnxSxQ33gMjhQiubIiHa9PKi
    e3wAn0D/j7v666GX+4dYnmDmx5pGSLaN
    =0GSP
    -----END PGP SIGNATURE-----

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,864

    Default Re: Customizing a bash shell prompt (PS1)

    Quote Originally Posted by VampirD View Post
    for root you must read and modify /etc/bash.bashrc
    I may be wrong, but I doubt this. /etc/bash.bashrc would be a central default for everybody, thus not only root, but all other users also. Thus when you want this prompt to be the default for all your users (root, yourself, your spouse, your children, whoever has a user id on the system) this is the correct place (but beware, updates could destroy this and thus, like the file itself says, do this in /etc/bash.bashrc.local).

    Every user can do this individualy in his/her ~/.bashrc as you found (and thus overriding any default you may have put in /etc/bash.bashrc). That is also true for root. When there isn't none, create it. Putting in it only the statements you need is enough.
    Henk van Velden

  4. #4
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,864

    Default Re: Customizing a bash shell prompt (PS1)

    As an addition. The fact that there is no ~/.bashrc for root is most probably because one should not use many statements when root logs in. This to avoid root not being able to log in when the system is in big problems and many things normaly available will simply not be there. Thus allways handle anything done with root with care.

    Remind the rule: when it is not needed to do things as root, don't do it using root. Changing it's prompt is one thing that is definitely not needed. And allthough it might look very innocent what you are doing, be carefull.
    Henk van Velden

  5. #5

    Default Re: Customizing a bash shell prompt (PS1)

    Quote Originally Posted by VampirD View Post
    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    for root you must read and modify /etc/bash.bashrc

    -----END PGP SIGNATURE-----

    Just as a reference, there is even a warning written on the /etc/bash.bashrc talking about some issues that might happen if you perform such change...

    # /etc/bash.bashrc for SUSE Linux
    #
    # PLEASE DO NOT CHANGE /etc/bash.bashrc There are chances that your changes
    # will be lost during system upgrades. Instead use /etc/bash.bashrc.local
    # for bash or /etc/ksh.kshrc.local for ksh or /etc/zsh.zshrc.local for the
    # zsh or /etc/ash.ashrc.local for the plain ash bourne shell for your local
    # settings, favourite global aliases, VISUAL and EDITOR variables, etc ...

  6. #6
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    19,650
    Blog Entries
    14

    Default Re: Customizing a bash shell prompt (PS1)

    Quote Originally Posted by pedrivo View Post
    Just as a reference, there is even a warning written on the /etc/bash.bashrc talking about some issues that might happen if you perform such change...

    # /etc/bash.bashrc for SUSE Linux
    #
    # PLEASE DO NOT CHANGE /etc/bash.bashrc There are chances that your changes
    # will be lost during system upgrades. Instead use /etc/bash.bashrc.local
    # for bash or /etc/ksh.kshrc.local for ksh or /etc/zsh.zshrc.local for the
    # zsh or /etc/ash.ashrc.local for the plain ash bourne shell for your local
    # settings, favourite global aliases, VISUAL and EDITOR variables, etc ...
    You're replying to a > 5 year old thread. Closing the subject.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •