Stage 7 · Lesson 1 of 8
Anatomy of a script
A is a text file full of commands that run in order. Its first line, the #!/usr/bin/env bash, says which program should run the file. Make it executable with chmod +x backup.sh, then run it with ./backup.sh.
You need the ./ because the current folder is not on your PATH. Put scripts you use often in ~/bin or ~/.local/bin, and add that folder to PATH. Write your scripts for rather than the plain sh shell, unless they must run on very minimal systems.
Common trapwriting a script in syntax on a Mac and then running it with Bash on a server.
A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- GuideFreeGreg's Wiki: BashGuide
Greg's Wiki (Wooledge) · Beginner
A careful, accurate Bash guide that teaches the habits that avoid most scripting bugs
- CourseFreeThe Missing Semester of Your CS Education
MIT · Beginner
The shell tools and scripting lecture, with exercises that build useful small scripts
Practise
Keep handy
Also worth your time
- roadmap.sh: Shell / BashGo deeper
The scripting side of the shell map: arrays, traps, parameter expansion and more