Bash (Bourne Again Shell)

botond published Jan. 2018, 07, 11:19 p.m. time

Bash is a Unix shell and command language written by Brian Fox as part of the GNU Project to replace the previously used Bourne shell. It first appeared in 1989, then became the default shell for most Linux distributions, Solaris 11 and Apple macOS (formerly OS X). It is also made for Windows 10.

Bash is a command processor that usually runs in a text window where the user can enter various commands by typing commands (CLI). You can also execute commands from Bash files, these files are called shell scripts. Like all Unix shells, it supports filename extension, pipelines, documents here, command substitutions, variables, control structures, condition checking, and loops. He inherited the keywords, syntax, and other basic functions of the language from the Bourne Shell. It got other functions, such as history handling, from csh and ksh. Bash is a POSIX-compliant shell, but it has many extensions.

The name of the shell is an acronym, Bourne Again Shell, which means "born again" of the Bourne shell.

In September 2014, a vulnerability was discovered in version 1.03 (August 1989), which resulted in many attacks on the Internet. The bugs were soon fixed, but not updated on all computers.

 

Running modes

Depending on the circumstances, Bash can be run in several modes.

Interactive login mode

Interactive login mode is when someone with a username and password (or with a public key) logs into the shell and interacts with it, so it gives commands to the shell, runs programs, and so on. When you log in, the scripts are executed in the following order:

  1. / Etc / profile (if exists)
  2. ~ / .Bash_profile (if it is not then the next :)
  3. ~ / .Bash_login (if it is not then the next :)
  4. ~ / .Profile

So it runs the first of the first and last of the last three, which exists. These files set different user environment variables (PATH, etc.), PROMPT, and other things that need to be executed once when the user logs on to the system. These can be, for example, system status messages, etc., which do not have to be displayed each time a terminal window is opened, for example.

When the user exits, the ~ / .Bash_logout file if it exists.

Interactive (non-login) mode

In this mode, Bash starts when, for example, you are already logged in to the desktop environment on a Linux computer and open a terminal from the menu. In this case, the above scripts do not run, but the following are executed each time you open a terminal window:

  1. /etc/bash.bashrc (if exists)
  2. ~/.bashrc (if exists)

These files can be used to set up environment variables, prompts, aliases, and everything you need to open each terminal window.

Non-interactive (non-login) mode

In this mode, for example, Bash starts from automated processes (for example, a shell script is started from cron) when it is not assumed that you can request input from the keyboard or if anyone will see the output of the process at all. In this case, Bash reads out the "BASH_ENV" environment variable and, if it finds a value, tries to execute it as a filename. So, it behaves as if the following command were executed:

if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi

However, the PATH environment variable is not used to find the filename.

It is also worth noting here that if you use a non-interactive shell with the "--login" option, Bash will try to run the login shell startup files. This is useful, for example, if you want to use the environment variables set for login shells in automatically started shell scripts.

Non-interactive (login) mode

This mode of operation can be created when, for example, additional commands are given as input to the ssh command. In this case, the specified commands are run on the remote server in a non-interactive, but login shell, and then their output is returned when exiting. In this case, the standard input to ssh is not the keyboard, but a string passed as a parameter or even piped.

For example, the following startup files do not run in this mode:

  • ~/.bashrc: Also, when this starts, there is a check at the beginning, which exits the script in non-interactive mode.
  • ~ / .Profile