Learn Bash

Learn what a shell is, how Bash fits into the Linux ecosystem, and why automating tasks with shell scripts saves you time.

What Is a Shell?

A shell is a program that sits between you and the operating system kernel. It reads the commands you type, asks the kernel to carry them out, and shows you the result. Every time you open a terminal window, you are talking to a shell.

Bash, short for 'Bourne Again SHell', is the most widely used shell on Linux and is also available on macOS and on Windows through WSL. It replaced the older Bourne shell (sh) in the late 1980s, adding features such as command history, tab completion, arrays, and richer scripting syntax.

Why Write Bash Scripts?

  • Automate repetitive tasks such as backups, deployments, and log rotation
  • Glue together other command-line tools without writing a full program
  • Run consistently on almost every server, container, and cloud image
  • Require no compiler or build step, just a text file and an interpreter
  • Give you fine-grained control over processes, files, and system administration

Your First Script

$ echo '#!/bin/bash' > hello.sh
$ echo 'echo "Hello, Bash!"' >> hello.sh
$ chmod +x hello.sh
$ ./hello.sh
Hello, Bash!
Note: The first line of a script, #!/bin/bash, is called a shebang. It tells the operating system which interpreter should run the file, so you can execute the script directly with ./hello.sh instead of typing bash hello.sh every time.

Interactive Shells vs. Scripts

You can use Bash two ways: interactively, typing one command at a time and reading the result immediately, or non-interactively, by saving commands in a script that runs from start to finish without you watching each step. Both modes use exactly the same syntax and commands.

Checking Your Shell

$ echo $SHELL
/bin/bash
$ bash --version
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu)

Running a Script Two Ways

$ bash hello.sh
Hello, Bash!
$ ./hello.sh
Hello, Bash!
ShellCommon NameNotes
shBourne ShellOriginal Unix shell from 1977; minimal feature set
bashBourne Again ShellDefault on most Linux distributions; adds scripting features
zshZ ShellDefault on macOS; highly customizable, mostly bash-compatible
dashDebian Almquist ShellLightweight sh replacement used for fast boot scripts

Exercise: Bash Introduction

What does "Bash" stand for?

Frequently Asked Questions

Is Bash worth learning if I already know Python?
Yes, for different jobs. Bash is unbeatable for gluing commands together, moving files and automating anything you would otherwise type at a terminal. Python takes over once logic gets complex, because Bash's handling of data structures and error cases gets awkward fast.
What is the difference between Bash and the terminal?
The terminal is the window; Bash is the program interpreting what you type into it. Other shells such as zsh and fish do the same job with different features. Most Bash knowledge carries over to them, because the core commands come from the system, not the shell.
Do I need Linux to learn Bash?
No. macOS ships with a Unix shell, and Windows runs Bash through WSL or Git Bash. The commands you learn work the same way across all of them, with occasional differences in the tools that ship by default.