[comp.bugs.sys5] Quoted space

rcodi@yabbie.rmit.oz (Ian Donaldson) (09/17/88)

From article <450@gt-ford.gtisqr.UUCP>, by stu@gtisqr.UUCP (Stu Donaldson):
> As I said, my solution was to create /bin/test.  Here is a copy,
> it is incredibly simple.
> 
> 	:
> 	# /bin/test
> 	if [ $* ]
> 	then
> 	  exit 0
> 	else
> 	  exit 1
> 	fi
> 
> As you can see, it relies on the test command implimented within
> the shell.  

Whilst it is functionally compatable with a real /bin/test most of the
time, it does fall down when quoted strings containing white space are passed 
as arguments.

eg:
	newtest "hello there" = "hello there"

But this is really a problem with $* breaking the arguments up.

From sh(1) man page, under the section on Quoting,

	"$*" is equivalent to "$1 $2 ..."
and     "$@" is equivalent to "$1" "$2" ...

So the script should really be:

	:
 	# /bin/test
 	if [ "$@" ]
 	then
 	  exit 0
 	else
 	  exit 1
 	fi

This version works much better.

Ian D

det@hawkmoon.MN.ORG (Derek E. Terveer) (09/19/88)

Hey!  This is great!  No flames or any other assorted nasty verbage....

Thanks for the info.  Yes -- i was stupid and didn't realize that /bin/test was
the culprit (and [, for that matter).  So what i did was simply create the file
that almost everyone suggested should be:

$ cat /bin/test
test $@

and things are spiffy again.

Summary:  compressdir is not buggy, my lack of /bin/test was the bug.

derek
-- 
Derek Terveer		det@hawkmoon.MN.ORG
			w(612)681-6986	h(612)688-0667

"A proper king is crowned" -- Thomas B. Costain