4

So at work I have two web servers that I am able to ssh into.

Both are RHEL 6.5

When I log into one, it shows this:

[username@ldvweb01 /]$ 

When I log into the other one it shows:

-bash-4.1$ 

I find it way more elegant when it shows the first one. How do I switch between the two? Can someone explain this to me?


After running this echo $PS1 these are the results

-bash-4.1$ echo $PS1
\s-\v\$

and

[appadmin@ldvcatweb01 /]$ echo $PS1
[\u@\h \W]\$

After checking for the differences between both home directories. I found that there was no .bashrc or .bash_profile in the home directory.

So I copied the ones from the previous server.

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

and

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions

I am guess that it just pulls the default bash settings from /etc

Thanks for all your help.

6

The bash prompt is configured by the PS1 environment variable. You can get the prompt you desire by adding

export PS1="[\u@\h \W]\$ "

to your .bashrc file (located in your user's home directory).

The full list of special characters that you can use for your prompt can be found in the official Bash documentation.

4

Assuming your login shell on both machines is bash, it's the PS1 environment variable that is different. This variable dictates the format of your prompt.

You can use echo $PS1 to see what PS1 is set to on the first machine, then use export PS1=... to set it to the same value on the second machine. To make this change permanent, you should add the export command to your .bashrc file (or possibly your .profile file, which is sourced by login shells - it depends on your configuration.)

Edit: According to your comment, what you need to do to get the exact same prompt on your second machine as on your first machine, is the command

export PS1="[\u@\h \W]\$"

You can make it permanent as already explained.

3

Your home folder may not be identical on each system. You can check .bashrc or .bash_profile scripts are handle on each server. for the prompt you need to include export PS1="\u@\h \w> " in your bash login script (.bash_profile)

You may want to have your home directory on a NFS mount to be able to see similar environment on each system.

  • This helped me a lot! Those files didn't exist! Thanks! – Arian Faurtosh Sep 29 '14 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.