Prefer [[ ... ]]:
if [[ -f "$file" ]]; then
echo "File exists"
fi
-f regular file, -d directory, -e exists-r readable, -w writable, -x executable[[ "$a" == "x" ]]
[[ -n "$s" ]] # non-empty
(( n > 10 )) # arithmetic context
if [[ "$mode" == "prod" ]]; then
run_prod
elif [[ "$mode" == "dev" ]]; then
run_dev
else
echo "Unknown mode: $mode" >&2
exit 2
fi
case "$1" in
start) do_start ;;
stop) do_stop ;;
*) echo "Usage: $0 {start|stop}" >&2; exit 2 ;;
esac
for f in *.log; do
[[ -e "$f" ]] || continue
echo "$f"
done
while IFS= read -r line; do
echo "line=$line"
done < input.txt
until ping -c1 1.1.1.1 >/dev/null 2>&1; do
sleep 1
done
break, continuereturn (functions), exit (script)