<br><br><div class="gmail_quote">On Fri, Oct 8, 2010 at 10:09 PM, Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br><br><div class="gmail_quote"><div><div></div><div class="h5">On Fri, Oct 8, 2010 at 9:02 PM, K. K. Subramaniam <span dir="ltr"><<a href="http://kksubbu.ml" target="_blank">kksubbu.ml</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Saturday 09 Oct 2010 4:06:37 am Eliot Miranda wrote:<br>
> Bert is very probably right. If you're suing bourne/bash then look up<br>
> the difference between $*, "$*", $@ and "$@". To preserve spaces you need<br>
> to use $@/"$@" (depending on context" not $*. Also within your script you<br>
> can use IFS to prevent space being a separator.<br>
</div>$@ always uses space as word separator while $* uses the first letter of IFS<br>
variable. Otherwise they are the same. Smalltalk uses spaces for separator so<br>
$@ will do.<br></blockquote><div><br></div><div><br></div></div></div><div>No. $@ expands to the argument list as supplied to the current command:</div></div></blockquote><div><br></div><div><br></div><div>I should have written</div>
<div> "$@" expands to the argument list as supplied to the current command:</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote">
<div><br></div><div><div> * Expands to the positional parameters, starting from one. When</div>
<div> the expansion occurs within double quotes, it expands to a sin-</div><div> gle word with the value of each parameter separated by the first</div><div> character of the IFS special variable. That is, "$*" is equiva-</div>
<div> lent to "$1c$2c...", where c is the first character of the value</div><div> of the IFS variable. If IFS is unset, the parameters are sepa-</div><div> rated by spaces. If IFS is null, the parameters are joined</div>
<div> without intervening separators.</div><div> @ Expands to the positional parameters, starting from one. When</div><div> the expansion occurs within double quotes, each parameter</div>
<div> expands to a separate word. That is, "$@" is equivalent to "$1"</div><div> "$2" ... </div></div><div><br></div><div>So when invoking a command from within a shell wrapper one should use "$@" to pass on the parameters as this preserves whitespace within parameters.</div>
<div>e.g.</div><div>-----------8<----------- printargs -----------8<-----------</div><div><div>#!/bin/sh</div><div>while [ $# -gt 0 ]; do</div><div> echo " ""$1"</div><div> shift</div><div>
done</div></div><div>-----------8<----------- wrapper -----------8<-----------</div><div><div>#!/bin/sh</div><div>echo '$*'</div><div>printargs $* </div><div>echo '"$*"'</div><div>printargs "$*"</div>
<div>echo '$@'</div><div>printargs $@</div><div>echo '"$@"'</div><div>printargs "$@"</div></div><div>-----------8<-----------</div><div>$ wrapper "hello world" hello world</div>
<div>prints:</div><div><div>$*</div><div> hello</div><div> world</div><div> hello</div><div> world</div><div>"$*"</div><div> hello world hello world</div><div>$@</div><div> hello</div><div> world</div>
<div> hello</div><div> world</div><div>"$@"</div><div> hello world</div><div> hello</div><div> world</div></div><div><br></div><div><br></div><div>HTH </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Subbu<br>
</blockquote></div><br>
</blockquote></div><br>