A shell script to automate file tasks
A text file of shell commands, such as cp, mv or rm, that run in order each time the script is run, so file tasks like backups can be automated.
Understanding A shell script to automate file tasks in WA Computer Science ATAR Unit 1
What it does: The two commands sit on separate lines and run top to bottom each time the script runs, so the copy happens first and the move second. The for loop sets f to each .txt file in turn, so one cp command backs up every matching file. A shell script holds a series of shell commands. Running it executes them one after another, so file tasks can be automated. cp copies a file and leaves the original in place. mv moves it, so the original is no longer in its old location. In a shell script there must be no spaces around the = sign when assigning a variable.
Common mistakes: The first line of a shell script must be the shebang #!/bin/bash, with # first and then !. Written as !#, the system cannot tell which shell should run the script. A variable's value is read by putting $ in front of its name. Without the $, cp looks for a folder literally named SRC. It should be cp $SRC/*.txt $DEST.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 315–470) and word search (Modules 100–470).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
shell scriptFill in the Blanks
Spot the Error
Student with a class code? Join your class →