Logic Cheatsheet
Logic Cheatsheet
LOGIC
KEY DEFINITIONS
LIST OPERATORS
TEST COMMANDS
“a command that can be used in bash to compare
different pieces of information”
Syntax:
[ EXPRESSION ]
Operators to use:
Example Script:
#!/bin/bash
Script: If file1.txt equals file2.txt AND file3.txt, then delete file2.txt and file3.txt
#!/bin/bash
Script: If file1.txt equals file2.txt OR file3.txt, then delete file2.txt and file3.txt
#!/bin/bash
case "$number" in
"") echo "You didn't enter anything!"
[0-9]) echo "you have entered a single digit number" ;;
[0-9][0-9]) echo "you have entered a two digit number" ;;
[0-9][0-9][0-9]) echo "you have entered a three digit number" ;;
*) echo "you have entered a number that is more than three digits" ;;
esac
1
It’s very important to remember to use a $ in front of
the variable name otherwise the case statement won't
work, as it cannot access the variable’s value
2
Remember to wrap the expansion of the variable
name in double quotes to avoid word splitting issues
3
Patterns follow the same rules as globbing patterns.
4
Patterns are evaluated from top to bottom , and only
the commands associated with the first pattern that
matches will be run.
5
*) is used as a “default” case, and is used to hold
commands that should run if no other cases match.