Bash (short for "Bourne Again SHell") is an interactive command interpreter and command language developed for Unix-like operating systems. Supported by the Free Software Foundation and created in 1989 by Brian Fox for the GNU Project, it is designed as a completely free software alternative for the Bourne shell, sh, and other proprietary Unix shells. Having gained widespread adoption, Bash is commonly used as the default login shell for numerous Linux distributions. It also supports the execution of commands from files, known as shell scripts, facilitating automation. The Bash command syntax is a superset of the Bourne shell's syntax, from which all basic features of the Bash syntax were copied. As a result, Bash can execute the vast majority of Bourne shell scripts without modification. Some other ideas were borrowed from the C shell, its successor tcsh, and the Korn Shell. It is available on nearly all modern operating systems, making it a versatile tool in various computing environments.
Definitions
ASCII, strings and numbers
Any series of characters is called a "string", or sometimes a "string literal". In Unix-like operating systems, all characters, printable and non-printing, except for a few such as the null character and forward slash /, can be used in filenames. In addition, all strings are case-sensitive. Bash, like many other programming languages, uses zero-based numbering.
Control+key combinations The Control+key functionality is provided by GNU Readline and is available in interactive mode only. Certain keypress combinations allow a user to operate Bash to use tab completion and to search the command history.
Tab ↹ – Activate tab completion ↑ – Scroll up (i.e. backward) in the command history ↓ – Scroll down (i.e. forward) in the command history Ctrl+r – Search the command history Some keypress combinations also allow a user to operate the terminal emulator in order to move the cursor within the terminal window and to control the emulator program. By default, these keypress combinations in Bash mirror those of Emacs. Default keybindings for control codes include:
Ctrl+f – Move the cursor one character to the right Ctrl+b – Move the cursor one character to the left Alt+f – Move the cursor one word to the right Alt+b – Move the cursor one word to the left Ctrl+a – Move the cursor to the beginning of the current commandline Ctrl+c – Cancels the current command and presents a new prompt Ctrl+d – Closes the current Bash instance, possibly also closing the terminal-emulator Ctrl+e – Move the cursor to the end of the current commandline Ctrl+q – Wake the terminal; buffered keypresses are then processed Ctrl+s – Put the terminal to sleep Ctrl+w – Remove one word to the left of the cursor Ctrl+z – Stop a foregrounded process Vi keybindings are also available and can be enabled by running set -o vi.
Syntax When Bash reads a full command line, the complete string is broken down into tokens. "Tokens" are identified using, and separated from each other using metacharacters. As of Bash 5.3, the 10 metacharacters are the space, tab, and newline, as well as the following characters: |&;()<> "Blanks" are composed entirely of unquoted metacharacters, "operators" each contain at least one unquoted metacharacter and "words" may not include any unquoted metacharacters. In practice, Bash breaks down full command strings into tokens or groups of tokens that do contain metacharacters and tokens or groups of tokens that do not contain any metacharacters—called "words". From there it further breaks words down into more specific, meaningful pieces like command names, variable assignment statements, etc. The two blanks are space and tab.
Operators Control operators perform a control function. They can be either a newline or one of the following: ||, &&, &, ;, ;;, ;&, ;;&, |, |&, (, or ). Redirection operators redirect the input or output streams. They include <, >, &>, <<, and <<<.
Words A word is a sequence of (non-meta-) characters treated as a single unit by the shell. A reserved word is a kind of a word that has a special meaning to the shell. A name is a kind of a word separate from reserved words. Names (A) consist solely of letters, underscores and numbers, (B) begin with either a letter or an underscore, and (C) may not begin with a number. Also called identifiers, names may be used for naming variables and functions. Sixteen of the twenty-two "reserved words", which may be characters or words are as follows:
Names may only contain the characters ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_. In the following example of a full command string, metacharacters have a comma placed above them, ,, reserved words have a caret placed beneath them, ^, and other tokens have a backtick placed also beneath them, `.
Subshells A "subshell" is an additional instance of the shell which has been initialized by a current instance of the shell. When a "parent" shell creates a subshell, or a "child" shell, an exact copy of the parent's environment information is re-created and becomes the environment of the subshell. In Bash, in non-arithmetic contexts, one can force the use of a subshell by enclosing a full command string in single parentheses.
For this simple case, the preceding two commands are equivalent, however, use of subshells can have certain unexpected side effects. There are numerous different forms of syntax which can cause the initialization of a subshell. A non-comprehensive list of operators that cause the initialization of a subshell is as follows:
Subshells syntax, (), for example, would initialize a subshell: Piping syntax, A | B, would initialize multiple subshells, one for each separate command in the pipeline:
Expansion
… excerpt ends here. Continue reading the full article.

