We are running a system which has our Linux & Unix Boxes authenticate against AD and because we have numerous different versions of Unix/Linux, we have to default to /bin/sh to make sure that the logins always work no matter the Server. I am looking to setup a .profile on RHEL to check to see what shell is set to at login and if its not bash, to switch to bash. I am not having any luck google searching for a method to do this and my shell scripting is on the weaker side.


How does one check for shell and switch at login without the control of the passwd file?


Untested. Edit your ~/.profile ...

if [ -x /bin/bash ]; then
  exec bash
  • This does work, as long as there is no recursion happening because of login scripts but I found out its a moot point because the server has /bin/sh -> /bin/bash
    – thebtm
    May 10 '16 at 20:29
  • 1
    Bash, when invoked as /bin/sh, tries to mimic sh, though. There's a difference in how it will execute scripts. Just saying.
    – tink
    May 10 '16 at 20:55

Do you mean something like which bash >/dev/null && exec bash? Or is the output of getent passwd of any use to you?

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