# Shell Scripts, Perl and Lua

> Small languages that do boring jobs for you, or live inside other programs. Shell scripts and PowerShell, Perl for text, and Lua for games.

**Course:** [Programming Languages](https://learn.benibix.com/learn/development-languages)  
**Time:** 12 min

**After this lesson you can:**

- Write a small shell script that runs commands
- Say how PowerShell differs from a shell script
- Say where Perl and Lua are used

## Which small languages automate jobs

A shell script is a file of commands that the shell runs one after another. The commands are the same ones you would type by hand, such as copy this folder or delete old logs. Put 10 of them in a file, and one command runs all 10. On Linux and macOS, the usual shell is Bash or a close cousin.

Shell scripts are glue. They start programs, move files and check results, and they run on almost every server with nothing to install. They get hard to read past a hundred lines or so. Then a language like Python is the better tool.

PowerShell is Microsoft's shell and script language, and it now runs on Windows, macOS and Linux. Its big difference is what passes between commands. A Bash command hands the next one plain text. A PowerShell command hands over objects with named parts, such as a file's name and size, so there is no text to pick apart.

Perl was made in 1987 for working with text, and it grew famous for finding and changing patterns fast. For years it was the glue of the early web and of system jobs. Its code can be very short and very hard to read. It is less common for new work today, but plenty of old scripts still run.

Lua is small, fast and built to live inside another program. It started in Brazil in 1993. A game engine written in C++ can let designers write levels and rules in Lua without touching the engine. Add-ons for big online games are written in it. Luau, a language built from it, runs a popular game platform.

All four are interpreted, so you edit and run with no build step. Lua, like R, counts lists from 1. A good habit for any script is to stop at the first failed command, rather than carry on and make things worse.

The classic shell mistake is a space in a file name. A script that deletes the old report can split the name in two and remove the wrong files. Wrap every file name in quote marks.

```bash
#!/bin/bash
# backup.sh: copy today's work to the backup drive
set -e                       # stop at the first failed command
day=$(date +%F)
cp -r "$HOME/work" "/mnt/backup/work-$day"
echo "Backed up to work-$day"
```
Four commands you could type by hand, saved in one file. The quote marks keep names with spaces in one piece.

![On the left, the same four commands typed by hand every evening, marked about 5 minutes a day. On the right, the same four commands saved in a file called backup.sh, run with one line, bash backup.sh, marked one command.](https://learn.benibix.com/diagrams/lang-shell-script.svg)

### Example: Lucy's nightly clean-up

Lucy deletes old log files on 6 servers by hand each Friday, typing the same 3 commands on each one. It takes about 20 minutes.

She writes a 12 line shell script and schedules it to run every night. The job now takes no time, and it never skips a server.

**Words in this lesson:** [Shell Script](https://learn.benibix.com/term/development/shell-script), [PowerShell](https://learn.benibix.com/term/development/powershell), [Perl](https://learn.benibix.com/term/development/perl), [Lua](https://learn.benibix.com/term/development/lua)

**Question:** What does PowerShell pass from one command to the next?

**Answer:** Objects with named parts, such as a file's name and size. Bash passes plain text that the next command must pick apart. PowerShell passes objects, so the next command can ask for a part by name.

---

Source: https://learn.benibix.com/learn/development-languages/shell-scripts-perl-and-lua
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-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
