Skip to content
Toolsbeginner

What is Bash?

Updated Nov 30, 20263 min readBased on official documentation
What is Bash?

In short

Bash is a shell, a program that reads commands you type and runs them on your computer. The name stands for Bourne-Again SHell. It is the default shell on the GNU operating system and runs on most versions of Unix, and it can also be used to write small programs called scripts.

Bash is a command language interpreter. That means it reads the lines you type, works out what they mean, and runs the programs they name. If you have ever opened a terminal window and typed a command, you were probably talking to a shell. Bash is one of the most common shells in the world, and you will meet it on Linux, on macOS, and in many Windows setups that offer a Unix-style environment.

What the name means

The name Bash is an acronym for "Bourne-Again SHell". It is a playful nod to Stephen Bourne, who wrote the original Unix shell called sh. Bash keeps much of that older shell's behavior, so scripts written for sh often run in Bash without changes. On top of that base, Bash adds features borrowed from other shells, such as the Korn shell and the C shell, along with a few features of its own.

How a shell works

At its simplest, a shell is a program that expands text and then executes commands. You type a line, the shell splits it into words, replaces things like variable names and file patterns with their values, and then starts the program. The result is printed back to your screen or sent somewhere else.

A shell does two jobs at once. First, it acts as a command interpreter, giving you a way to use the many small tools that come with Unix-style systems. Second, it is a programming language. It has variables, loops, conditions and functions. You can save a list of commands in a file, make the file executable, and then run it like any other program. These files are called shell scripts.

Shells can run in two modes. In interactive mode, they wait for you to type commands at a prompt. In non-interactive mode, they read commands from a file or from a string and run them without waiting for input.

A simple example

Try a few commands to see how Bash behaves. The following lines print the current directory, list its files, and count the lines in a text file:

pwd
ls -l
echo "Hello from Bash"
wc -l notes.txt

The word echo prints its arguments. The quotes around the message keep it together as one piece of text. The wc command counts lines, and the -l option tells it to count lines rather than words or bytes. None of these commands is part of Bash itself. Bash finds each program, starts it, and waits for it to finish.

Built-in commands

Most commands you type are separate programs stored in folders such as /bin. Some commands, however, are built into the shell. These are called builtins. Examples include cd, which changes the current directory, and exec, which replaces the shell with another program. These commands must live inside the shell because they change the shell itself. A program running on its own could not change the directory of the shell that started it.

Common mistakes

Beginners often forget that Bash treats spaces as separators. A file name with a space in it must be quoted, or Bash will read it as two separate words. Another common mistake is to assume that a command you wrote in one shell works the same way in every other shell. Bash is largely compatible with sh, but it has features that sh does not, so a script that uses them may fail when run under a stricter shell.

Remember also that the shell reads your input before running anything. A small typo can change the meaning of a whole line, so it is worth reading a command carefully before pressing Enter.

Where to go next

Bash is a good first shell to learn because it is available almost everywhere. If you also manage remote servers, you may want to read our guide to SSH, which lets you run a shell on another computer over a secure connection. If you later work with build tools for web projects, our page on Vite explains how a modern build tool is started from the command line.

The Bash manual is long, and it is worth reading the early chapters first. The introduction and the sections on basic shell features cover everything a new user needs before moving on to scripting and advanced options.

FAQ

Is Bash the same as the terminal?

No. The terminal is the window where you type and read text. Bash is the program that runs inside that window and interprets the commands you enter.

Do I need to install Bash?

On most Linux systems Bash is already installed and is often the default shell. On macOS and Windows you may need to open a terminal or install a compatible environment to use it.

What is the difference between Bash and sh?

sh is the older Unix shell that Bash was built to stay compatible with. Bash includes many extra features, such as improved scripting and interactive tools, that sh does not provide.

Can I write programs in Bash?

Yes. Bash has variables, loops, conditions and functions, so you can save commands in a file and run them as a script. Bash is well suited to small automation tasks.

Sources

This page is based on the official documentation below. Read it for full detail.

Bash — official documentation ↗
blozhikDeveloper news from across the web, explained. Every story links to its original sources.