Bash
Bourne Again Shell
- Pronunciation
- BASH
In short
Bash is a Unix shell and scripting language, the default on most Linux systems, used both to type commands interactively and to automate tasks with scripts.
What is Bash?
Bash was written by Brian Fox for the GNU Project and released in 1989 as a free replacement for the Bourne shell, which is where the pun in its name comes from. It became the default shell on most Linux distributions and on macOS for many years; macOS switched its default to zsh in 2019, which is largely compatible for everyday use.
As a language, Bash glues programs together. Commands are connected with pipes, grep error app.log | wc -l, their output can be captured in variables with $(...), and scripts add variables, conditions, loops and functions. A script starts with a shebang line such as #!/usr/bin/env bash and is made executable with chmod +x.
That makes Bash the natural tool for automation: build and deploy steps, CI pipelines, container entry points, server setup and small data chores. In the Stack Overflow developer surveys, Bash/Shell regularly ranks among the most used languages, because nearly every developer writes some.
A common misconception is that Bash is fine for programs of any size. Its quoting rules, word splitting and error handling are full of traps: unquoted variables break on spaces in file names, and by default a failing command doesn't stop the script. Quoting every variable, starting with set -euo pipefail, checking scripts with ShellCheck and switching to Python once logic grows complex avoid most problems.
Key takeaways
- Bash is a Unix shell and scripting language released in 1989.
- It is the default command line on most Linux systems.
- Pipes, variables, loops and functions glue programs together.
- It is the everyday tool for build, deploy and CI automation.
- Quote variables, use set -euo pipefail and ShellCheck to avoid its traps.
Example
#!/usr/bin/env bash
set -euo pipefail # stop on errors, unset variables and failed pipes
log_dir="${1:-/var/log/myapp}"
threshold=10
count=$(grep -c "ERROR" "$log_dir/app.log" || true)
if (( count > threshold )); then
echo "Too many errors: $count" >&2
exit 1
fi
for file in "$log_dir"/*.log; do # quoted, so spaces in names are safe
gzip --keep "$file"
done
echo "Archived logs, $count errors found."Readers ask
What is the difference between Bash and a shell?
A shell is any program that reads commands and runs them. Bash is one specific shell; others include sh, zsh, fish and PowerShell.
Is Bash a programming language?
Yes. It has variables, conditions, loops and functions, so it is a full scripting language, though it is designed for running and combining commands rather than for large applications.
Can I use Bash on Windows?
Yes, through the Windows Subsystem for Linux (WSL), which runs a real Linux environment, or through Git Bash, which comes with Git for Windows.
See also
- ShellOperating Systems, p. 27A shell is a program that reads commands typed by a user or written in a script and asks the operating system to run them, usually through a text interface.
- LinuxDevOps & Cloud, p. 33Linux is an open-source operating system kernel that powers most servers, cloud platforms, containers, and Android phones, usually packaged as a distribution.
- PowerShellProgramming Languages, p. 24PowerShell is Microsoft's command-line shell and scripting language for automating administration, passing objects rather than plain text between commands.
- Environment VariableDevOps & Cloud, p. 20An environment variable is a named value set outside a program, by the operating system or runtime, that the program reads to configure its behavior.
- CI/CDDevOps & Cloud, p. 9CI/CD is a set of automated practices that build, test, and release code changes frequently, so software can be delivered to users quickly and safely.
- Cron JobBackend & APIs, p. 9A cron job is a command or script that runs automatically on a repeating schedule, such as every night at 2 a.m., defined by a five-field cron expression.
Spotted a mistake or something missing on this page?Suggest an edit