This patch does the following:
1) $var -> ${var}
2) use double quotes around variables to prevent globbing and word splits
3) Use ${@} instead of ${*} when looping over elements to prevent whitespace problems
4) Instead of `[ expr1 -o expr2 ]` use `[expr1] || [expr2]` as the former may have side effects
5) Save a pipe by using awk's / / functionality to search for a string instead of using grep piped to awk