Scott Prater writes:
>
> I believe the "unary operator expected" error is occurring in the line:
>
> if [ $9 = "-u" ]; then
>
> Whenever I do shell scripting, I always use the trick explained in _Unix
> Power Tools_: instead of
> if [ $9 = "-u" ]
> do
> if [ "X$9" = "X-u" ]
>
> That way, the test will never fail, even if $9 doesn't exist.
If you're using quotes, then you don't need the X kludge. For example;
if [ "$9" = "-u" ]
Will work just fine. As long as you have quotes around them, a null
string will be passed as an argument to the test.
BTW, I always use "set -u" at the top of my shell scripts, and the
default construction to avoid errors:
set -u
if [ "${9:-}" = "-u" ]
That way, misspelt shell variables will turn up a LOT sooner.