Skip to content

What is bash (the Bourne-Again SHell)?

  • by

The bash shell is one of the most commonly used shells in Linux and other Unix-like operating systems. bash stands for Bourne-Again SHell and is a free software shell that was written as a replacement for the original Bourne shell (sh).

bash provides a command-line interface for interacting with the operating system and is a powerful tool for performing a wide range of tasks, from basic file management to complex system administration. bash is known for its features, such as command line completion, history, and advanced scripting capabilities, which make it a popular choice for both novice and advanced users.

bash is the default shell on many Linux distributions and is widely available on other Unix-like operating systems. If you are using a Linux-based operating system, chances are you are already using bash as your default shell. To start a bash shell, simply open a terminal window and start typing commands.

bash provides many features that make it a powerful and flexible shell, including:

  1. Command line editing: bash provides advanced command line editing capabilities, including the ability to recall previous commands, move the cursor, and edit the current command line.
  2. Environment variables: bash provides a way to set and manage environment variables, which are used to configure the shell and other programs. Environment variables can be set using the export command, and their values can be retrieved using the echo command or the $ notation.
  3. Aliases: bash provides a way to create aliases for commands, which can simplify repetitive tasks and make the shell more user-friendly. Aliases can be created using the alias command, and their values can be displayed using the alias command without any arguments.
  4. Command history: bash provides a command history mechanism that allows you to recall and reuse previous commands. The command history can be accessed using the up and down arrow keys, and you can search the command history using the CTRL + R key combination.
  5. Scripting: bash provides a rich scripting language that can be used to automate tasks and perform complex operations. bash scripts can be executed by passing the script file to the bash interpreter, or by making the file executable and running it directly.
  6. Built-in commands: bash provides a number of built-in commands that provide basic functionality, such as cd for changing directories, ls for listing files, and echo for printing output.
  7. Pipes and redirection: bash provides the ability to redirect input and output and to pipe the output of one command into the input of another command. This makes it possible to perform complex operations using a combination of simple commands.

Shell script programming

Shell script programming is a powerful way to automate tasks and perform complex operations in Linux and other Unix-like operating systems. Here is a tutorial on how to write shell scripts in bash:

  1. Create a new script file: To create a new shell script, you can use a text editor, such as nano or vi, to create a new file with a .sh extension. For example, to create a new script named, you could run the following command:
  1. Add a shebang line: The first line of your shell script should be a shebang line, which specifies the shell interpreter that should be used to run the script. For bash scripts, the shebang line should be as follows:
  1. Add commands: After the shebang line, you can add commands to your script. These commands can be any valid bash commands, including built-in commands, such as cd and ls, and external commands, such as grep and sed. For example, the following script prints the current working directory:
  1. Save and close the script file: After you have added the commands to your script, save the file and close the text editor.
  2. Make the script executable: To make the script executable, you need to set the execute permission for the script file. You can do this using the chmod command:
chmod +x
  1. Run the script: To run the script, simply enter the following command:

These are just a few examples of the features provided by bash. To learn more about bash and its capabilities, you can consult the bash manual page by running the following command:

man bash

Logo: Free Software Foundation, FAL, via Wikimedia Commons