If Statement in Shell

Level 379 keystrokes

if statement checks conditions and executes different code branches.

Shell code

# [ -f "config.json" ] is true if config.json exists and is a regular file
1if [ -f "config.json" ]; then
# Runs when the file exists; prints: Config found
2 echo "Config found"
3else
# Runs when the file is missing
4 echo "Config missing"
# fi (if spelled backwards) ends the if block
5fi

Output

Config found
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Shell code and how often they appear.

  • "× 6
  • -× 1
  • ;× 1
  • .× 1
  • [× 1
  • ]× 1

More Shell examples at level 3

← Shell typing practice