# Shell Script

> A file of commands the shell runs in turn, so you type less.

**Field:** Software Development  
**Category:** Languages  
**Also known as:** Bash Script, Bash Scripting, sh Script, .sh File

## Think of it like

It is like a to-do list you give a helper. The helper does each line in order.

## Definition

A shell script is a text file full of commands that a shell runs one after another. Anything you can type at the command line can go in it. The first line, called the shebang, names the shell to use, such as Bash. You make the file runnable once, then run it by name. Scripts save time on jobs you do again and again.

## Example

Jack writes a three-line script that copies his notes folder into a dated backup. A timer runs it every night.

## Example code

```bash
#!/bin/bash
echo "Backing up notes"
tar -czf "notes-$(date +%F).tar.gz" ~/notes
```

The first line picks Bash. The last line packs the notes folder into a dated file.

## Why it matters

Most server and build jobs are glued together with shell scripts. They turn a list of steps into one command.

## Common mistake

Leaving out quotes around names. A file name with a space then splits in two, and the script works on the wrong thing.

## Three principles

- **Commands in a file.** Same as typing them.
- **Shebang first.** Names the shell to use.
- **Run it again.** One name for many steps.

## Related terms

- [Shell](https://learn.benibix.com/term/infrastructure/shell)
- [Command Line](https://learn.benibix.com/term/infrastructure/command-line)
- [PowerShell](https://learn.benibix.com/term/development/powershell)
- [Scripting Language](https://learn.benibix.com/term/development/scripting-language)

## Told apart from

- [Shell Script vs PowerShell](https://learn.benibix.com/compare/shell-script-vs-powershell): People think PowerShell is just the Windows version of a Bash shell script, and it is not. Both run commands one after another from a file. A Bash command hands the next one plain text, which has to be picked apart. A PowerShell command hands over objects with named parts, such as a file's name and size. PowerShell now runs on macOS and Linux too.

## Taught in

- [Shell Scripts, Perl and Lua](https://learn.benibix.com/learn/development-languages/shell-scripts-perl-and-lua): Programming Languages, 12/12

![Four labelled shelves of languages. Data science: R, MATLAB and Julia, beside a small bar chart. Functional: Haskell, Scala, Elixir, beside an arrow that turns a list into a new list. Shell and scripting: shell script, PowerShell, Perl and Lua, beside a terminal prompt. Close to the hardware: assembly language and Objective-C, beside a chip and a phone.](https://learn.benibix.com/diagrams/dev4-language-families.svg)

---

Source: https://learn.benibix.com/term/development/shell-script
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
