tags:

views:

151

answers:

3

I have this in .bashrc;

PS1='$'

However, I see this still in terminal:

mas-macbook:some/path mas$

I want

$

A: 

I think you need the export keyword:

export PS1='$'
strager
The code does not work at the top of .bashrc.
Masi
What do you mean, Masi? Are you getting an error, or is it just that the prompt isn't changing?
paxdiablo
If the latter, see my answer on how to ensure .bashrc is running. If the former, please show us the error.
paxdiablo
A: 

You may have to escape the $ symbol. This works in my system... PS1="\$"

If that don't work, please run the command 'echo $PS1' and let us know the results. You may also have to send the .bashrc file - it possible that you have set the PS1 variable before including the global /etc/bashrc file. If that's the case, the global file will overwrite the variable. You will have to set the PS1 variable after including the /etc/bashrc file.

Binny V A
echo $PS1 gives \h:\W \u\$
Masi
Okay, if you've got PS1='$' in .bashrc and it's not set that way when the shell hands over control to you, either .bashrc isn't running or something else is running after which changes it back. See my answer for debugging this.
paxdiablo
+2  A: 

PS1 should already have been exported long before you get to your .bashrc file, at least for a login shell. In that case, setting PS1 should simply overwrite the value (not its export status).

One thing to keep in mind is that bash itself does not run your .bashrc file for a login shell. The actual sequence of execution is:

  • /etc/profile, if there.
  • first of ~/.bash_profile, ~/.bash_login or ~/.profile.

I'm fairly certain that, if you want .bashrc to run for a login shell, it has to be sourced from one of those above.

For example, /etc/profile may call /etc/profile.local or all the scripts in the /etc/profile.d/ directory. Similarly, my .bash_profile calls the following, if they exist:

  • /etc/bash.bashrc
  • ~/.bashrc

with the following snippet:

if [ -e /etc/bash.bashrc ] ; then
    source /etc/bash.bashrc
fi
if [ -e "${HOME}/.bashrc" ] ; then
    source "${HOME}/.bashrc"
fi

When I change PS1 and echo "hello" in my .bashrc, but comment out the sourcing of it in .bash_profile, the prompt doesn't get changed (nor the string printed) when I log in. When I uncomment the sourcing, I get both the string printed and the prompt changed when I log in.

To make sure that your .bashrc is called for your login shells, put that echo hello statement just after setting PS1, then log in to check.

If it is being called when you log in, you can execute "export -p" from your shell to get a list of all the exported variables - make sure PS1 has a "declare -x" in front of it. If not, just change your .bashrc to export it as well:

export PS1='$'

If it's already exported, then something is changing it after your set statement. In that case, you'll need to actually look at the login execution path to see what's getting called before it gives you control.

paxdiablo
One bug arised. My Git stop to work after I inserted the code. Do you know my?
Masi
That depends. What code did you actually insert and in what file? If it's the echo of hello, that was a debugging aid and shouldn't be left in .bashrc.
paxdiablo
I by accident commented a export PATH statement. There is no problem in your code. Thank you!
Masi