control
if test 2 -gt 1; then printf 'yes\n'; else printf 'no\n'; fi
That is the whole shape Everything below is a variation on it
if
test and [ compare values
[[ is the Bash version with fewer surprises
if [[ "$name" == "0x1RIS" ]]; then
printf 'known\n'
fi
case
case "$name" in
0x1RIS) printf 'known\n' ;;
*) printf 'unknown\n' ;;
esac
case beats a long chain of if when one value drives the decision
The ;; ends each branch
* catches everything else
for
total=0
for n in 1 2 3; do
total=$((total + n))
done
printf '%s\n' "$total"
Output:
6
$(( )) is arithmetic
No spaces needed inside the expression
while
count=0
while test "$count" -lt 3; do
count=$((count + 1))
done
A while loop keeps going while the condition succeeds
For a fixed list, prefer for
Next
Chains and subshells in 08 processes
Posted