0

I'm using this in my .profile to switch to bash on login:

case $- in
  *i*)
    # Interactive session. Try switching to bash.
    if [ -z "$BASH" ]; then # do nothing if running under bash already
      bash=$(command -v bash)
      if [ -x "$bash" ]; then
        export SHELL="$bash"
        exec "$bash -l"
      fi
    fi
esac

Is there a way to get the following to execute automatically after the bash shell opens?

PS1='\[\e[1;91m\][\u@\h \w]\$\[\e[0m\] '

I put the line in a .bash_profile but it does not change the prompt.

3
  • 1
    have you tried to run "chsh" to change your login shell? Commented Sep 7, 2016 at 18:53
  • not installed, this is on a very old solaris box Commented Sep 7, 2016 at 19:14
  • 1
    i wonder how old your bash is.. what if you have to export the PS1 variable? do you have truss installed? maybe use truss to see if it reads in .bash_profile.. or add debug echo statements to bash_profile to see if it is being executed Commented Sep 7, 2016 at 19:19

2 Answers 2

3

For interactive shell, put the PS1 line in your ~/.bashrc, not in ~/.profile and source it :

source ~/.bashrc 

(or loggoff/in)

Moreover, if you'd like to permanently change your shell :

chsh -s /bin/bash

or edit as root with vipw or editor /etc/passwd

2
  • 1
    it worked with .bashrc vs .bash_profile Commented Sep 7, 2016 at 20:17
  • Invoking chsh -s /bin/bash [username] may throw the error chsh: can only change local entries; use ypchsh instead.. Commented Aug 8, 2017 at 14:08
2

This should just work:

...
export SHELL="$bash"
PS1='\[\e[1;91m\][\u@\h \w]\$\[\e[0m\] ' exec $bash -l
...

If you have root or similar privilege:

usermod -s $bash dave111

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.