Quoted space (was: Re: compressdir bug?)
Ian Donaldson
rcodi at yabbie.rmit.oz
Sat Sep 17 17:11:22 AEST 1988
>From article <450 at gt-ford.gtisqr.UUCP>, by stu at 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
More information about the Comp.bugs.sys5
mailing list