ITSK 1601- Shell Scripting
- Variables/Types
- Syntax: var=value
- Only type is strings.
- Get value by preceeding name with a $: echo $var
- Use only numbers letters and underscore in name
- Computation
- Old way: expr 5 + $i
- Problems include:
- slow
- requires spaces between words
- variables require $ to proceed name
- must quote special symbols like *.
- Better: Bash's arithmatic mode: echo $[5+i]
- Solves all of expr's problems.
- Only liability is that it only works in bash.
- If you have bash you should use its math mode.
- Only works for integers.
- Floating point: echo "scale=10;(77-32)/1.8" | bc
- The bc calculator is a general purpose infinite digit calculator.
- Can use for general purpose work.
- Accepts expressions from standard input.
- Advanced features, variables, functions.
- scale variable sets precision.
- Exit codes:
- Every program returns a exit code.
- Codes have different meanings for each code.
- Generally a code of 0 represents OK or True.
- example: grep
- Exit codes are used for selection and repetition.
- The testcommand
- test does a wide variety of test operations: numbers, strings, files
- Strings: = !=
- Integers: -eq,-ne,-ge,-gt,-lt,-le
- Files: existance, type, empty, readable/writable/executable
- use and an or to string together multiple tests.
- Uses return codes for results.