Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I set .bash_profile to

 exec env -i HOME=$HOME TERM=vt100 PS1='\h' /bin/bash

But when I login, it also show:

 lfs@sam:~$ env
 TERM=vt100
 PWD=/home/lfs
 PS1=${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 
 SHLVL=1
 HOME=/home/lfs
 _=/usr/bin/env
 lfs@sam:~$

What happened?

How to set PS1 when login?

Thank you~

share|improve this question
2  
PS1 is usually set in .bashrc, not .bash_profile. .profile type files are for setting environment variables. PS1 is a shell variable, not an environment variable. Chances are, you have a .bashrc that is also setting PS1. –  jw013 Jul 25 '12 at 16:41
add comment

1 Answer

This value of PS1 is set by the bash system-wide configuration file /etc/bash.bashrc. You can override it by setting it from your ~/.bashrc.

PS1 is a shell variable. Its meaning depends on the shell. It should normally not be exported since it is not supposed to be in process's environments, though you can get away with it if you only ever use one shell.

Note that bash is rather quirky about configuration files: if you start a login instance of bash, it reads only /etc/profile and ~/.bash_profile, and ~/.profile if there is no ~/.bash_profile. If you start a non-login interactive instance, it reads /etc/bash.bashrc (if configured to do so) and ~/.bashrc. In order to get your interactive settings in login instances of bash, you should put this code in your ~/.bash_profile:

if [ -r ~/.profile ]; then
  . ~/.profile
fi
case $- in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac

The shell variable $- contains the letter i to indicate that the shell is interactive.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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