[squeak-dev] script arguments with spaces
Eliot Miranda
eliot.miranda at gmail.com
Sat Oct 9 05:15:59 UTC 2010
On Fri, Oct 8, 2010 at 10:09 PM, Eliot Miranda <eliot.miranda at gmail.com>wrote:
>
>
> On Fri, Oct 8, 2010 at 9:02 PM, K. K. Subramaniam <kksubbu.ml at gmail.com>wrote:
>
>> On Saturday 09 Oct 2010 4:06:37 am Eliot Miranda wrote:
>> > Bert is very probably right. If you're suing bourne/bash then look
>> up
>> > the difference between $*, "$*", $@ and "$@". To preserve spaces you
>> need
>> > to use $@/"$@" (depending on context" not $*. Also within your script
>> you
>> > can use IFS to prevent space being a separator.
>> $@ always uses space as word separator while $* uses the first letter of
>> IFS
>> variable. Otherwise they are the same. Smalltalk uses spaces for
>> separator so
>> $@ will do.
>>
>
>
> No. $@ expands to the argument list as supplied to the current command:
>
I should have written
"$@" expands to the argument list as supplied to the current command:
>
> * Expands to the positional parameters, starting from one.
> When
> the expansion occurs within double quotes, it expands to a
> sin-
> gle word with the value of each parameter separated by the
> first
> character of the IFS special variable. That is, "$*" is
> equiva-
> lent to "$1c$2c...", where c is the first character of the
> value
> of the IFS variable. If IFS is unset, the parameters are
> sepa-
> rated by spaces. If IFS is null, the parameters are
> joined
> without intervening separators.
> @ Expands to the positional parameters, starting from one.
> When
> the expansion occurs within double quotes, each
> parameter
> expands to a separate word. That is, "$@" is equivalent to
> "$1"
> "$2" ...
>
> So when invoking a command from within a shell wrapper one should use "$@"
> to pass on the parameters as this preserves whitespace within parameters.
> e.g.
> -----------8<----------- printargs -----------8<-----------
> #!/bin/sh
> while [ $# -gt 0 ]; do
> echo " ""$1"
> shift
> done
> -----------8<----------- wrapper -----------8<-----------
> #!/bin/sh
> echo '$*'
> printargs $*
> echo '"$*"'
> printargs "$*"
> echo '$@'
> printargs $@
> echo '"$@"'
> printargs "$@"
> -----------8<-----------
> $ wrapper "hello world" hello world
> prints:
> $*
> hello
> world
> hello
> world
> "$*"
> hello world hello world
> $@
> hello
> world
> hello
> world
> "$@"
> hello world
> hello
> world
>
>
> HTH
>
>>
>> Subbu
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20101008/fe160682/attachment.htm
More information about the Squeak-dev
mailing list
|