# Shell script

> A text file full of terminal commands that the computer runs one after another.

- Level: Intermediate
- Topics: Software
- URL: https://tidbit.legios.com.ar/shell-script/
- In Spanish: [Script de shell](https://tidbit.legios.com.ar/es/shell-script/)

A **shell script** is a plain text file containing commands you could type at the command line, saved so the computer can run them all in order with a single instruction. If every morning you copy a folder, compress it and upload it to a server, you can write those three commands in a file like `backup.sh` and run just that file instead.

The first line usually says which shell should read it, for example `#!/bin/bash` for Bash, the default shell on most Linux systems (Macs have used Zsh by default since 2019, and it understands most of the same syntax). After marking the file as executable with `chmod +x backup.sh`, you run it with `./backup.sh`. Scripts can also use variables, `if` conditions and loops, so they can decide what to do and repeat steps over many files.

Shell scripts are the glue of software work. They install programs, start servers, run tests in CI pipelines, rotate logs and schedule nightly jobs. They are quick to write but easy to get subtly wrong: a missing quote around a file name with spaces can make a script act on the wrong files. For anything long or complicated, teams usually switch to a language like Python.

## An analogy

A recipe card taped to the fridge. Instead of remembering each step every time, you write the steps down once and anyone (or any computer) can follow them exactly.

## Keep in mind

- A text file of shell commands, run in order with one instruction.
- Starts with a line like `#!/bin/bash` naming the shell that runs it.
- Common for installs, backups, deploys and scheduled jobs.
- Great for short automation; long logic is better in a full language.

## Go deeper

- [Writing shell scripts (LinuxCommand.org)](https://linuxcommand.org/lc3_writing_shell_scripts.php)
- [Shell script on Wikipedia](https://en.wikipedia.org/wiki/Shell_script)

## Related terms

- [Command line](https://tidbit.legios.com.ar/command-line/): Controlling a computer by typing text commands instead of clicking icons.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [Linux](https://tidbit.legios.com.ar/linux/): A free, open source operating system that runs most of the internet's servers.
- [CI/CD](https://tidbit.legios.com.ar/ci-cd/): Automation that builds, tests and ships every code change, so releases become routine.
- [Python](https://tidbit.legios.com.ar/python/): A popular programming language known for being easy to read and quick to write.
- [Backup](https://tidbit.legios.com.ar/backup/): A separate copy of your data, kept so you can get it back when the original is lost.
- [Deployment](https://tidbit.legios.com.ar/deployment/): Getting a new version of software from the team's computers to real users.
