ArticleslgStudy

computer science

Bash (Unix shell)

Bash (Unix shell) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Bash (Unix shell) rather than just read about it. In short: 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.

Bash (Unix shell) — main illustration
Bash (Unix shell) — illustration

Key takeaways

  • Bash (Unix shell) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Bash (Unix shell) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Bash (Unix shell) from memory before moving on to harder problems.

Reference excerpt

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.

Illustrations

Bash (Unix shell) illustration

Worked examples

Example 1 — a first encounter with Bash (Unix shell)

Start with the simplest possible case. Write down what Bash (Unix shell) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Bash (Unix shell) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Bash (Unix shell) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Bash (Unix shell)

In research
Bash (Unix shell) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Bash (Unix shell) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Bash (Unix shell) is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1989 software, Cross-platform free software, Domain-specific programming languages, so understanding it makes those chapters shorter.
In everyday life
Look for Bash (Unix shell) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Bash (Unix shell)” →

How to study Bash (Unix shell) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Bash (Unix shell) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Bash (Unix shell) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Bash (Unix shell) in simple terms?

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 th…

Why does Bash (Unix shell) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Bash (Unix shell)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Bash (Unix shell).

Tags

  • 1989 software
  • Cross-platform free software
  • Domain-specific programming languages
  • Dynamically scoped programming languages
  • Free software programmed in C
  • GNU Project software
  • Scripting languages
  • Software using the GNU General Public License
  • Text-oriented programming languages
  • Unix shells

Keep exploring