Question about 'test'

Martin Weitzel martin at mwtech.UUCP
Tue Dec 4 00:30:51 AEST 1990


In article <1779 at seti.inria.fr> deschamp at seti.inria.fr writes:
:
:In article <QPLIU.90Nov29205347 at phoenix.princeton.edu>,
:qpliu at phoenix.princeton.edu (q.p.liu) writes:
:
:|> trying /bin/[ shows that it only checks if argv[0] == "[".
:
:   *Never* generalize :-). On my workstation (Sun 3/60 under SunOS 4.0.3):
:	$ test
:	$ [
:	test: ] missing
:
:What I do not understand is this:
:	$ '['
:	test: ] missing
:	$ PATH=/bin '['
:	test: ] missing
:	$ /bin/[
:	$
:
:Why no complaint in the last case ?

This shows exactly what original poster tried to say (as I understood).
To make it a bit clearer, the source-code of "test" must look like

	if (!strcmp(argv[0], "[")) {
		if (strcmp(argv[--argc], "]") {
			/* complain about missing "]" and exit */
			.....
		}
	}
	/* parse arguments; run tests as required */
	.....

In your last experiment argv[0] is "/bin/[" and not simply "[", hence no
comlaint.
-- 
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.unix.shell mailing list