Chapter 8
- if statement
if command then command command ... fi
- exit status
- Used by the if statement
- Also available in the $? variable
- test command
- Can also use [ ... ]
- String tests:
string = string strings are the same string != string strings are not the same string string is not null -n string string is not null -z string string is null - Numeric tests: -lt -gt -eq -le -ge -ne
- Files tests:
-e file file exists. -d file file is a directory. -f file file is an ordinary file. -L file file is a symbolic link. -s file file has nonzero length. -r file file is readable by the process. -w file file is writable by the process. -x file file is executable. - Logical operators:
! Negation (NOT) -a AND -o OR
- else statement
if command then command command ... else command command ... fi
- exit - end script immediately
- elif statement
if command then command command ... elif command then command command ... elif command then command command ... else command command ... fi
- case statement
case value in pat1) command command command;; pat2) command command command;; pat3) command command command;; pat4) command command command;; esac- You can use wildcard style pattern matching: * ? [..]
- Can test multiple patterns using pat1 | pat2
- the null command : - use it when you need a command but don't want to do anything.
- && and || - Logical AND and OR for commands