Bash

Bash (Bourne-again Shell) is a command-line shell/programming language by the GNU Project. Its name is a homaging reference to its predecessor, the long-deprecated Bourne shell. Bash can be run on most UNIX-like operating systems, including GNU/Linux.

Invocation

Bash behaviour can be altered depending on how it is invoked. Some descriptions of different modes follow.

If Bash is spawned by login in a TTY, by an SSH daemon, or similar means, it is considered a login shell. This mode can also be engaged using the -l/--login command line option.

Bash is considered an interactive shell when its standard input and error are connected to a terminal (for example, when run in a terminal emulator), and it is not started with the -c option or non-option arguments (for example, bash script). All interactive shells source /etc/bash.bashrc and ~/.bashrc, while interactive login shells also source /etc/profile and ~/.bash_profile.

Configuration files

See section “6.2 Bash Startup Files” in /usr/share/doc/bash/bashref.html (online link) and GregsWiki:DotFiles for a complete description.

File Description Login shells (see note) Interactive, non-login shells
/etc/profile Sources application settings in /etc/profile.d/*.sh and /etc/bash.bashrc. Yes No
~/.bash_profile Per-user, after /etc/profile. If this file does not exist, ~/.bash_login and ~/.profile are checked in that order. The skeleton file /etc/skel/.bash_profile also sources ~/.bashrc. Yes No
~/.bash_logout After exit of a login shell. Yes No
/etc/bash.bashrc Depends on the -DSYS_BASHRC="/etc/bash.bashrc" compilation flag. Sources /usr/share/bash-completion/bash_completion. No Yes
~/.bashrc Per-user, after /etc/bash.bashrc. No Yes

 

Note: 

Shell and environment variables

The behavior of Bash and programs run by it can be influenced by a number of environment variables. Environment variables are used to store useful values such as command search directories, or which browser to use. When a new shell or script is launched it inherits its parent’s variables, thus starting with an internal set of shell variables[1].

These shell variables in Bash can be exported in order to become environment variables:

VARIABLE=content
export VARIABLE

or with a shortcut

export VARIABLE=content

Environment variables are conventionally placed in ~/.profile or /etc/profile so that other Bourne-compatible shells can use them.

See Environment variables for more general information.

 

Customize per-command

Note: Using the complete builtin may cause conflicts with bash-completion.

By default Bash only tab-completes file names following a command. You can change it to complete command names using complete -c:

~/.bashrc
complete -c man which

or complete command names and file names with -cf:

complete -cf sudo

See the Bash man page for more completion options.

Calogero Scarnà
Calogero Scarnà
Articoli: 299

Newsletter

Inserisci il tuo nome e il tuo indirizzo email qui sotto e iscriviti alla nostra newsletter