48

I was surprised that I didn't find this question already on the site. So, today $ came up after I logged in as a new user. This was unexpected because my main user's prompt starts with username@computername:~$.

So, how do I switch from this other shell to bash?

8
  • 8
    Just because $ came up rather than username@computername:~$ doesn't mean it wasn't bash. The exact formatting of the prompt is set by the PS1 variable, which can be set up or customized differently for different users.
    – frabjous
    Commented Aug 30, 2010 at 2:58
  • 3
    @mouche Re: @frabjous echo $SHELL to find out what your current shell is. Commented Aug 30, 2010 at 12:41
  • 1
    @mouche @frabjous and beginning with a $ is actually common for bash, some non bash shells like zsh use the % out of the box, I believe other shells use other things. Commented Aug 30, 2010 at 12:48
  • 1
    @mouche being /bin/sh often doesn't mean much that's usually a symlink to something else. I'd type ls -l /bin/sh to see what it's a symlink to. In some cases being a symlink to something changes its behavior, I don't think bash is that way. Commented Aug 30, 2010 at 16:22
  • 3
    @xenoterracide - Using bash as /bin/sh disables many bash features (it goes into POSIX compliance mode).
    – Chris Down
    Commented Sep 24, 2011 at 18:04

3 Answers 3

71

Assuming the unknown shell supports running an absolute command, you could try: /bin/bash

To change the default shell, I would use chsh(1). Sample usage: chsh -s /bin/bash $USER

3
  • 1
    Does chsh permanently change the shell or just for the current session?
    – mouche
    Commented Aug 30, 2010 at 2:35
  • 10
    @mouche Permanently; it changes your entry in /etc/passwd Commented Aug 30, 2010 at 2:36
  • @mouche, chsh(1) will only allow to change to a shell that is listed in /etc/shells (and is available, presumably). chsh -l lists the alternatives. Be careful, some (like nologin) are defined for accounts that should never be used to login (nice way to lock yourself out), there might be local additions for special uses.
    – vonbrand
    Commented Feb 29, 2016 at 15:56
20

You type in bash. If you want this to be a permanent change the default shell to /bin/bash by editing /etc/passwd.

Here's some snippets from my /etc/passwd:

avahi:x:84:84:Avahi daemon:/:/bin/false
xenoterracide:x:1000:100::/home/xenoterracide:/bin/zsh
postgres:x:88:88::/var/lib/postgres:/bin/zsh
bob:x:1001:1001::/home/bob:/bin/bash
usbmux:x:140:140:usbmux user:/:/sbin/nologin

The very last field contains the shell, Modifying the field after the last : to a valid or invalid shell will work. /bin/false and /sbin/nologin both mean the user doesn't have a real login shell, although if pam is not set up right this doesn't mean they can't login (I reported a bug on this in Arch Linux, because you can login graphically without having a login shell). /bin/bash and /bin/zsh are both valid shells, see /etc/shells for a list of valid shells on your systems. Here's my /etc/shells if you're interested.

/bin/sh
/bin/bash
/bin/ksh
/bin/zsh
/bin/dash

Yes you can use chsh or usermod to do the same things, please remember these are just structured text files, and TIMTOWTDI.

3
  • 11
    You probably want to use chsh instead of manually editing passwd Commented Aug 30, 2010 at 2:38
  • @Michael there are about 5 (POOMA) different ways to change the shell in /etc/passwd I didn't feel like listing any of them, because I always do it manually. chsh and usermod can both do it. Commented Aug 30, 2010 at 12:27
  • Messing around with configuration files is a Bad Idea(TM), an error might make the system unusable. Yes, it is often the only/fastest way, but then do it with extreme care.
    – vonbrand
    Commented Feb 29, 2016 at 15:58
16

If chsh or manually editing the config won't work, but a ~/.profile script is executed at login, add this line:

exec /bin/bash --login
3
  • After looking around for a while, this was the solution I needed. Thanks! Commented Aug 8, 2012 at 13:13
  • Great idea, specially if the shell selected sources that file on startup...
    – vonbrand
    Commented Feb 29, 2016 at 15:59
  • 3
    touch ~/.bash_profile or otherwise bash will exec itself in a loop: bash takes ~/.profile in case ~/.bash_profile doesn't exist.
    – alephreish
    Commented Dec 31, 2017 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .