funny in 'test'

Barry Margolin barmar at think.COM
Wed May 11 15:02:54 AEST 1988


In article <10778 at steinmetz.ge.com> davidsen at steinmetz.ge.com (William E. Davidsen Jr) writes:
>	if [ "$1" = "x" ]; then do something; fi
>A good reason
>never to put ANY shell variable in the first position of an = test.

Another common convention is to put an extra character onto the front
of both parts of the test, e.g.

	if [ "x$1" = "xx" ]; ...

That way, if $1 starts with a hyphen, this becomes something like

	if [ "x-d" = "xx" ]

Barry Margolin
Thinking Machines Corp.

barmar at think.com
uunet!think!barmar



More information about the Comp.unix.wizards mailing list