quoting, corrected function defs (still improper), use type over which, change echo calls to printf calls, use integer logic for UID tests.

Some quoting was inappropriately omitted for string variables.

use `function foo {' if you want the function keyword.
the most appropriate way is `foo() {'
Reference:
http://mywiki.wooledge.org/BashPitfalls#function_foo.28.29

in zsh, `which' is an alias for `whence -c' builtin. in bash, `which'
fork/execs to the command found in PATH. my new approach is a tiny
bit more verbose, but saves a subprocess for bash users. does anyone
but me care for this? meh.
integer comparisons with proper arithmetic test, printf instead of echo, function definitons.