04-23-04 11:35 PM
In article <PsidnTo4doDHGhTdRVn-hQ@comcast.com>,
"scott" <speedglide@comcast.net> wrote:
> for parameter in $*
> do
> echo $#
> eval echo \${$#}
> shift
> done
>
>
> if this is invoked as "./program a b c d" i would expext the output to be:
> 4
> d
> 3
> c
> 2
> b
> 1
> a
>
> but it is
> 4
> d
> 3
> d
> 2
> d
> 1
> d
>
> Can anyone explain this and help me get my expected output?
The first time through the loop, the arguments are:
a b c d
$# is 4, and $4 is d, so it prints 4 then d.
The second time through the loop, the arguments are:
b c d
because the shift command removed the first argument. Now $# is 3, and
$3 is d, so it prints 3 then d.
Do I need to go on?
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
[ Post a follow-up to this message ]
|