Re: Question.

From: rakesh sharma (sharma__r_at_hotmail.com)
Date: 10/04/03


Date: 4 Oct 2003 13:41:09 -0700

Gazza <gazza@192.168.1.1> wrote in message news:<29Bfb.6605$QH3.982@newsfep4-winn.server.ntli.net>...
> Hi,
>
> I am writing a BASH utility which will use any/all of it's execution
> arguments, $1, $2, $3, and so on. The problem is that my script needs to
> know how many, if any, set execution arguments have been passed to it. I
> could just use the following method:
>
> $1
> $2
> $3
> $4
> [and so on]
>
> . But what if there are five arguments, six, or seven, etc? I'd have to go
> on indefinately. I tried the following:
>
> count=1
> while ((count <= 4)); do
> echo "$"$count"
> count=$((count+1))
> done
>
> , but got the following output:
>
> $1
> $2
> $3
> $4
>
> . What I wanted, of course, was the _values_ of $1, $2, $3 and $4.
>
> Can anyone help?
>
> Yours,
> Gary Hayward.

count=1
while [ $# -ne 0 ]; do
    echo "\$$count => |$1|"
    count="`expr $count + 1`"
    shift
done