Change Shell To Bash in Linux / Unix

How do I switch from a ksh shell to bash on Linux or Unix system? How to change shells on Unix-like system?

A shell is nothing but a command that provides a text-only user interface (also known as “command line interface”) for Linux, MacOS, and Unix-like operating systems. Bash shell read commands such as ls, date and others typed into a terminal and then run them. That is the primary function of bash shell.

How do I fund out the default shell for a user?

Type the following command to find out the default shell for a user named vivek using the grep command and /etc/passwd file:
$ grep vivek /etc/passwd

$ ps -p $$
14314 pts/9 00:00:00 zsh

$ echo $0

All of the above output indicates that the shell is zsh for user named vivek in Linux operating system.

How do I see what shells are available on my system?

Type the cat command as follows:
$ cat /etc/shells
Sample outputs:

Fig.01: How to find list of available shells on Linux or Unix or MacOS?

How do I switch to a bash or different shell?

Type the name at the command line and then press the enter key. In this example, to change from any shell to the bash, type:

How to change shells on a Linux or Unix-like systems?

You can change your default shell using the chsh (“change shell” ) command as follows. The syntax is:
chsh -s {shell-name-here}
chsh -s {shell-name-here} {user-name-here}
chsh -s /bin/bash
chsh -s /bin/bash vivek

You can find full path to your shell using the following command:
type -a bash
type -a zsh
type -a ksh

Please note that a normal user may only change the login shell for her own account. The superuser (root) may change the login shell for any account using the following syntax:
$ sudo chsh -s /bin/bash raj

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....

How to Start and Enable Firewalld on CentOS 7

In this article, we discuss how to start and enable firewalld. It is highly recommended that you have a firewall protecting your server.Pre-Flight CheckThese...