ENES

Shell script

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

A small backup.sh file with three commands, run once from the terminal, which then copies, compresses and uploads files

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.

Keep in mind

Go deeper

Related terms

More in Software