Where to start First steps track · 15 stages
Linux Labs

Bash scripts: running, variables, arguments

cheat sheet · Ubuntu 24.04 · bash 5.2 https://lab.dimsanych.ru/en/wiki/bash-scripting/

Cheat sheet

  • #!/bin/bash # first line: what runs the file
  • set -euo pipefail stop at the first error
  • chmod u+x backup.sh allow running it
  • ./backup.sh "my file.txt" run it by path
  • bash backup.sh run it without the x bit
  • bash -n backup.sh check syntax without running
  • name="value"; echo "$name" a variable — in double quotes
  • for f in "$@"; do echo "$f"; done every argument, one at a time
Loading…