Linux, terminal and Git

Stage 7 · Lesson 3 of 8

Variables, arguments and input

Shell scripts and automation

In a script, set a with name="value", with no spaces around the =. Read it back with "$name", always inside . are the values passed to the script when you run it.

$1 is the first, $2 the second, "$@" is all of them and $# is how many there are. ${name:-default} gives a fallback value when a variable is empty. $(command) captures a command's output into a variable.

Check the arguments at the top of the script and print a short usage line if any are missing. Read secrets from , not from arguments, because arguments show up in lists and shell history.

Common trapunquoted variables, which break on spaces and turn empty values into dangerous commands.

A question to check yourself, an AI practice session and 2 cheat sheet entries 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?