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 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?

share|improve this question
6  
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 Aug 30 '10 at 2:58
1  
@mouche Re: @frabjous echo $SHELL to find out what your current shell is. –  xenoterracide Aug 30 '10 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. –  xenoterracide Aug 30 '10 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. –  xenoterracide Aug 30 '10 at 16:22
1  
@xenoterracide - Using bash as /bin/sh disables many bash features (it goes into POSIX compliance mode). –  Chris Down Sep 24 '11 at 18:04
show 2 more comments

3 Answers

up vote 24 down vote accepted

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 your_user

share|improve this answer
    
Does chsh permanently change the shell or just for the current session? –  mouche Aug 30 '10 at 2:35
6  
@mouche Permanently; it changes your entry in /etc/passwd –  Michael Mrozek Aug 30 '10 at 2:36
add comment

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.

share|improve this answer
    
Could you be more specific about how to edit /etc/passwd to make the change permanent? –  mouche Aug 30 '10 at 2:36
9  
You probably want to use chsh instead of manually editing passwd –  Michael Mrozek Aug 30 '10 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. –  xenoterracide Aug 30 '10 at 12:27
    
@mouche I updated my answer. –  xenoterracide Aug 30 '10 at 12:35
    
Great, @xenoterracide! That's super helpful. I like knowing how things work, but chsh is certainly quicker. –  mouche Aug 31 '10 at 1:58
add comment

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
share|improve this answer
    
After looking around for a while, this was the solution I needed. Thanks! –  PearsonArtPhoto Aug 8 '12 at 13:13
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.