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.
See the terminal emulator article for some general usage pointers.
When writing scripts, care should be taken to reference the correct interpreter on the first line, with a shebang. A script beginning with
#!/bin/shshould only use POSIX constructs and no 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 make it the tool of choice for many professionals.
The CLI provides a standardized, text-based interface, generally accessed through a terminal emulator (or virtual console). In this terminal generally is run a shell, which provides the user interface.
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 developed many of it's 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 the minimum skill is acquired from habitual use, 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 aim to provide simple, easily memorizable interfaces, who's options can be combined to achieve the desired functionality. The CLI generally follows a standard interface, to allow tight interaction between tools, and even provides help and manuals via options such as
--help, and man pages.
Modern shells allow powerful constructs, such as pipes, so diverse tools can interact seamlessly. Many utilities provide filtering and sorting of output.
Some CLI utilities may be interactive, either asking for basic input after execution, or effectively opening a command-specific sub-shell. Most utilities will take input from the command line, standard input, files, devices or the network and can output to the command line, or have their output redirected to a file or piped to other commands.
Gentoo provides a choice of shells, some of which are:
|bash||app-shells/bash||https://tiswww.case.edu/php/chet/bash/bashtop.html||The Bourne Again Shell, is the default shell on Gentoo. It is used by Portage, Gentoo's default package manager.|
|dash||app-shells/dash||http://gondor.apana.org.au/~herbert/dash/||The Debian Almquist Shell, a small, fast, and posix-compliant shell suited for startup scripts (as /bin/sh replacement).|
|fish||app-shells/fish||https://fishshell.com/||The Friendly Interactive SHell.|
|ksh||app-shells/ksh||http://www.kornshell.com/||The Original Korn Shell, 1993 revision (ksh93).|
|mksh||app-shells/mksh||https://www.mirbsd.org/mksh.htm||An actively developed free implementation of the Korn Shell, and well suited for scripting.|
|pwsh||app-shells/pwsh-bin||https://learn.microsoft.com/powershell/||Most shells assume "everything is a file"; PowerShell is an object-oriented shell and so "everything is an object". Now MIT-licensed and available on Linux.|
|tcsh||app-shells/tcsh||http://www.tcsh.org/||an enhanced version of the Berkeley C Shell (csh).|
|yash||app-shells/yash||https://yash.osdn.jp/||Yet Another SHell, is a POSIX-compliant command line shell written in C99 (ISO/IEC 9899:1999).|
|zsh||app-shells/zsh||http://www.zsh.org/||An advanced shell that is the chosen interactive shell for many users.|
For more shell options, see the output of the following command (eix required):
eix -cC app-shells
See the login article about how the environment is set up.
Changing the default system shell
Changing /bin/sh to something other than bash can cause rare issues with badly written scripts, e.g. scripts starting with
#!/bin/shbut using bash specific code. bug #526268
System administrators can change the default system shell using USE flags on app-alternatives/sh. This utility changes the system shell by replacing /bin/sh with a symlink to a different POSIX compatible shell.
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 be a symlink to dash from app-shells/dash app-alternatives/sh -bash dash
Changing a user's shell
Some shells, such as fish, can cause issues if directly set as the login shell. See the section#Caveats article for workarounds.
A user's default shell (aka login shell) can be changed on an individual basis using the chsh command. To change the login shell for the current user, type chsh and enter a correct path to the new shell. In the example below, a user named Larry the cow (Larry) is changing his login shell from /bin/bash to /bin/zsh:
Changing the login shell for larry Enter the new value, or press ENTER for the default Login Shell [/bin/bash]: /bin/zsh
chsh can be used by the super user account to change the login shell for any user.
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.