Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Conditionals in Bash

Insted of real conditionals in Bash we only have a way to some command was successful or not and the if will execute code based on this condition.

What does it mean a program is successful or not? Exit code 0 or anything else. $?

  • [[ ]]}
  • -e}
#!/usr/bin/env bash

filename=$1

if [[ -e $filename ]]; then
   echo "File $filename exists"
fi