2.19.2015

Switching between shells in linux



Linux/Unix Shell is compact closure of system utilities,calls,kernel which can be ported and command using shell commands. Different commands can be input through this where different hardware signals are been triggered in order to work on specific hardware task through linux hardware.

Although bash, the default shell on Linux, is highly versatile and can be used for almost anything, each shell has its own characteristics and there might be situations in which it is preferable to use some other shell, such as ash, csh, ksh, sh or zsh. For example, the csh shell has a syntax that resembles that of the highly popular C programming language, and thus it is sometimes preferred by programmers.

Sometimes it is useful to first determine the current default shell for a user. This can be accomplished by using the grep command (which is commonly used to search for specific text within files) to read the entry for the default shell for the current user's account in /etc/passwd (the file that stores information about users). For example, the following could be used to find the default shell for a user named janis:

grep janis /etc/passwd

grep might return a line something like janis:x:501:501::/home/janis:/bin/bash, which indicates that the shell is bash.

It can also be useful to see what shells are available on a particular system. This can be accomplished by using the cat command (which is commonly employed to read files) to read the /etc/shells file, which lists all shells installed on the system, as follows:

cat /etc/shells

All that is necessary for a user to switch to a different shell (assuming that it is already installed on the system) for the current session is to type its name at the command line and then press the ENTER key. Because a shell is an executable file (i.e., a program), the current shell launches it, and it then takes over from the current shell. For example, to change from any shell to the sh shell, all that is necessary is to type the following and then press the ENTER key:

sh

Upon changing shells, a different command prompt (i.e., the short text message at the left of each command line) may be shown, depending on the previous and new shells. For example, if the original shell were bash and the new shell is sh, the command prompt would change for a user george from something like [lin@localhost lin]$ to something like sh-2.05b$.

To return to the original shell, or any other one for that matter, all that is necessary is to just type its name and then press the ENTER key. Thus, for example, to return to the bash shell from the sh shell (or from any other shell), all that is required is to type the word bash and press the ENTER key, i.e.,

bash

Methods for permanently changing the shell may vary according to the system. However, in general, the first step is to determine the full path, also called the absolute path, to the shell, which is its location on the system relative to the root directory (i.e., the directory that contains all other directories and which is represented by a forward slash). The full path for each shell is shown in the /etc/shells file, and in the /etc/passwd file for those shells listed in it. In the previous example, the full path to the bash shell was /bin/bash.

Once the full path to the new shell has been determined, a user can change its default shell using the chsh (i.e., change shell) command as follows:

chsh

This results in a brief dialog in which the user is prompted first for its password and then for the full path of the desired new shell.

0 comments:

Post a Comment