A shell is a command-line interpreter that offers a text-based interface to users. It can be used as a command-line interface in a virtual console (or in a terminal emulator, over a serial connection, etc.), as a remote shell (over SSH, for example), or as a script interpreter (running prewritten commands).
Typically, the shell is the first program started after a user logs in at a terminal. The /etc/passwd file contains information defining the login shell for each user on the system. After login, a user can launch other shells from a terminal, change their login shell, or specify a shell to use under certain terminal emulators.
In Gentoo, the /bin/sh file is a symlink to the default system shell, and as such can link to one of several different POSIX shells. After following the Handbook the default shell will be bash.
When writing scripts, care should be taken to reference the correct interpreter on the first line by using a shebang. A script beginning with
#!/bin/sh should only use POSIX constructs without any bash specific code, for example.
The Command Line Interface
The Unix(like) command line interface (CLI) is a powerful, mature paradigm to interact with modern computers. The CLI maintains some notable advantages over graphically-based models, which makes it the tool of choice for many professionals.
The CLI has a rich history that predates even CRT screen technology, beginning on teleprinters. This long history has resulted in a sophisticated system, which has developed many of its characteristics along with the UNIX OS. Today, text is almost always entered with a keyboard, and output presented on a screen.
Though the learning curve may be steeper than for GUIs, once minimal skill is acquired the CLI provides all the commands available on a system right under the user's fingertips, without having to read and navigate menus.
CLI tools tend to provide simple, easily memorizable interfaces whose options can be combined to achieve desired functionality. The CLI generally follows a standard interface to allow tight interaction between tools. It also allows for accessing the manuals of tools via man pages, or more quickly and simply via
Some CLI utilities may be interactive, either by asking for basic input after execution or by opening a command-specific subshell. Most utilities take input from the command line, standard input, files, devices, or a network. Then they output either to the command line, or else have their output redirected to a file or piped to other commands.
Gentoo provides a choice of shells, some of which are:
|The Bourne Again Shell is the default shell on Gentoo. It is used by Portage, Gentoo's default package manager.
|The Debian Almquist Shell. A small, fast, posix-compliant shell suited for startup scripts (as /bin/sh replacement).
|The Friendly Interactive SHell.
|The Original Korn Shell, 1993 revision (ksh93).
|An actively developed free implementation of the Korn Shell, well suited for scripting.
|Most shells assume "everything is a file". PowerShell is an object-oriented shell where "everything is an object". Now MIT-licensed and available on Linux.
|An enhanced version of the Berkeley C Shell (csh).
|Yet Another SHell is a POSIX-compliant command line shell written in C99 (ISO/IEC 9899:1999).
|An advanced shell that is the chosen interactive shell for many users.
eix -cC app-shells
Changing /bin/sh to something other than bash can cause rare issues with badly written scripts, e.g. scripts starting with
#!/bin/sh but using bash-specific code. See . It may be safer to leave the system shell as the default bash, and set user login shells when creating users, or using the chsh command for existing users - see next section.
It's normal that only a handful of POSIX compatible shells will be available to be used with this method. See the next section on how to set user login shells, which allows setting more shells as default. Also note the above warning, and consider preferentially using the method from the next section to set any shell as default.
The "system shell" is used when executed from /bin/sh, such as by scripts that start with
#! /bin/sh. Changing the "system shell" will not change what shell users login to, and will not change what shell is set for new users either.
System administrators can change the system shell using USE flags on /bin/sh with a symlink to a different POSIX compatible shell.. This utility changes the system shell by replacing
USE flags for app-alternatives/sh /bin/sh (POSIX shell) symlink
To set a particular choice for /bin/sh use /etc/portage/package.use:
# Make /bin/sh a symlink to dash from app-shells/dash
app-alternatives/sh -bash dash
User's login shell
Some shells such as fish can cause issues if directly set as the login shell. See the caveats section of the fish article to see how to set it as a default shell safely.
Login-shell settings are stored in /etc/passwd.
Creating a user with a specific login shell
Login shells can be set when creating a new user with the useradd command (from ).
To create a user and specify their login shell:
useradd -s /bin/ksh -m larry
-s option indicates the path to the shell, the
-m option instructs the useradd command to create the new user's home directory if it does not already exist.
Setting an existing user's login shell
A user's login shell can be changed using the chsh command. To change the login shell for the current user, type chsh and enter the path to the new shell. In the example below, a user named larry is changing their login shell from /bin/ksh to /bin/zsh:
Changing the login shell for larry Enter the new value, or press ENTER for the default Login Shell [/bin/ksh]: /bin/zsh
chsh can be used to change the login shell for any user from the super user account (root).
The chsh command only allows shells listed in /etc/shells.
The output of a shell can, in some conditions, become corrupt. See the terminal emulator article for instructions to help fix this.
- GNU Coreutils — provide many of the basic commands of the UNIX(like) OS.
- Login — logging in to a shell, and setting up the default environment.
- Recommended tools — lists system-administration related tools recommended for use in a shell environment (terminal/console)
- Terminal emulator — emulates a video terminal within another display architecture (e.g. in X).
- util-linux — contains userspace utilities for Linux-specific system management, including device control, terminal logins, process management, and tty messaging.