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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 Aug 30 '10 at 2:58
2  
@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
3  
@xenoterracide - Using bash as /bin/sh disables many bash features (it goes into POSIX compliance mode). – Chris Down Sep 24 '11 at 18:04
up vote 45 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
9  
@mouche Permanently; it changes your entry in /etc/passwd – Michael Mrozek Aug 30 '10 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 Feb 29 at 15:56

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

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
    
Great idea, specially if the shell selected sources that file on startup... – vonbrand Feb 29 at 15:59

type in your shell and choose /bin/bash:

sh-3.2:~$ chsh
Enter the new value, or press return for the default
Login Shell [/bin/bash]: /bin/bash

This is a great guide to understand which possible shell you already have and how do you choose one Changing my shell in Linux

share|improve this answer
1  
Sorry, if your answer provide "just" a link, you should add it as a comment, or report here (text) the core content of the page you linking, this way it's avoided that a link change makes your post useful here : ) take care – lese Dec 10 '15 at 9:55
    
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Raphael Ahrens Dec 10 '15 at 10:12
    
Just because I still can't comment question. – DhiaTN Dec 10 '15 at 10:28

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.