Linux, terminal and Git

Stage 7 · Lesson 1 of 8

Anatomy of a script

Shell scripts and automation

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 zsh 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

Practise

Keep handy

  • Paste or run a script to catch quoting and error-handling bugs before they bite

  • Check what each part of an unfamiliar command does before you put it in a script

Also worth your time

Mark this stage as not done?