Linux Labs

Bash: text processing and scripts / Stage 5 of 9

Arguments, quotes and file checks

Not running Starting usually ~20 s
Leave the lesson

Step 7 of 7 · summary · 2 min

Summary

  • A script gets its arguments in $1, $2 and on, their number in $#, all of them separately in "$@". Without quotes an expanded value is split at spaces again.
  • [ -f "$f" ], -d, -e, -r, -s test a path before you work with it, and if … then … else … fi picks what to do.
  • The exit status is the script's answer: exit N sets it, and a usage line for a wrong call goes to the error stream through >&2.
  • At the start of the lesson the quotes in the call delivered my file.txt to report.sh whole, and the unquoted $@ and $f inside the script cut the name apart again.
Ubuntu 24.04
Loading…