In sh, is '[' a portable synonym for 'test'?

Roy Smith roy at phri.UUCP
Tue Oct 1 01:41:54 AEST 1985


	On my 4.2bsd system, the following do the same thing in sh because
/bin/[ is a link to /bin/test.  Test checks to see if it was called as "["
and in that case looks for the matching "]" at the end of the command.

	if test -r wombat; then echo I can read wombat; fi
	if [ -r wombat ]; then echo I can read wombat; fi

	This is not documented anywhere in the 4.2 manual (that I can find)
but seems to be common practice.  Is the "[]" form safe to use if you want
to make something portable?  My Sys5 manual (January 1983) notes the two
forms but mentions that the second is not recognized on all systems.  Does
anybody know on what systems it will fail?
-- 
Roy Smith <allegra!phri!roy>
System Administrator, Public Health Research Institute
455 First Avenue, New York, NY 10016



More information about the Comp.unix.wizards mailing list