funny in 'test'

William E. Davidsen Jr davidsen at steinmetz.ge.com
Wed May 11 04:47:46 AEST 1988


  I had a user find a good (?) one the other day. She has a shell script
which did something like:
	if [ "$1" = "x" ]; then do something; fi

  The value passed in as the first argument was "-d". Now, the construct
"-d =" should test for a directory named "=", followed by a barf on the
operator "x". This script in fact compared strings on a number of
systems, and blew up on only a few. I believe that it should fail, but
would like some opinions on this.

  I fixed it by inverting the test, but it really looks as though some
shells assume a precedence of operators in the shell. A good reason
never to put ANY shell variable in the first position of an = test.
-- 
	bill davidsen		(wedu at ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.unix.wizards mailing list