On Thu, Mar 14, 2002 at 11:25:51AM +0000, Philip Reynolds wrote:
> You can use function in bash and zsh (haven't used it in any other
> shells).
what i'm describing applies to sh, not sure of zsh.
> Defining this:
>> $ function blah {
> echo Hallo $* there
> }
i keep a copy of 'unix power tools' in the bathroom for something to leaf
through while 'thinking.' (i'm sure there's a better way to describe
that) anyway it was describing the merits of $@ vs. $*. i've always
used $*, but $@ seems better. not sure how it works exactly though.
here's my toy script:
#!/bin/sh
echo using '$*'
echo "$*"
for f in "$*"; do
echo $f
done
echo using '$@'
echo "$@"
for f in "$@"; do
echo $f
done
run it like so:
./foo.sh moo cow
./foo.sh "moo cow"
according to the sh man page:
* Expands to the positional parameters, starting from
one. When the expansion occurs within double
quotes, it expands to a single word with the value
of each parameter separated by the first character
of the IFS special variable. That is, ``$*'' is
equivalent to ``$1c$2c...'', where c is the first
character of the value of the IFS variable. If IFS
is null or unset, the parameters are separated by
spaces.
@ Expands to the positional parameters, starting from
one. When the expansion occurs within double
quotes, each parameter expands as a separate word.
That is, `` $@'' is equivalent to ``$1'' ``$2'' ...
When there are no positional parameters, ``$@'' and
$@ expand to nothing (i.e., they are removed).
any shell scripting gurus have comments on this? i've been kind of
curious since i read it.
kevin
--
kevin at suberic.net buffy: come on, can't you put your foot down?!
fork()'ed on 37058400 giles: it *is* down.
meatspace place: orbit buffy: one of these days you're going to have to
http://suberic.net/~kevin get a grown up car. --inca mummy girl
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!