Linux › Section K · Shell scripts › Topic K.3

Conditionals

Scripts earn their keep by making decisions: skip a file that is missing, refuse a bad option, act only when a pattern is found. In the shell every decision rests on one thing, the exit code of a command, and once you see that, if, test and case stop being mysterious.

In this topic

  • Decisions run on exit codes
  • The [ command
  • Worked example: the missing argument bug
  • Any command can be a test
  • elif: more than two branches
  • File tests
  • String and number tests
  • Worked example: a case dispatcher
  • bash extras: [[ ]] and (( ))
  • Common mistakes to avoid
  • Key takeaways

This topic is part of Wuanberri Pro. Checking your access…

← Previous topicNext topic →