$# question

$# holds the number of arguments passed into a shell. Is this value the index of an array? and if so, is there a way to determine the max index of the array so that I can know right off how many values were passed in? or do I have to sit in some sort of loop testing to see if $# is set, incrementing $# along the way? the goal here is to use the max index to define the iteration argument of a loop.

You weren't very specific, so I'll answer from the Bourne/Korn/zsh perspective.

No, as you already wrote, it's the number of arguments passed into the shell. (The array thing is a C-shell -ism.) You access the arguments by using the variables $1, $2, etc. If there are more than nine arguments, you can use ${10}, ${11}, etc. There are lots of ways to scan through the arguments looking for something.

I think all you need is something like this:

i=1
while [ $i -lt "$#" ] ; do
    eval arg=\${$i}
    # Do something with $arg here
    i=`expr $i + 1`
done

With Korn and Z shells, you get built in simple arithmetic and don't need to invoke expr.

Unless you need to hold on to the previous values in place (rare in practice), the more usual idiom is something like this:

while [ "$#" -gt 0 ]; do
    # Do something with $1 here
    shift   # Move $1 out, shifting $2->$1, $3->$2, etc
done

Re: the quotes around $#: The Vim syntax hilighting barfs on this expression when it is unquoted.

Thanks for the information you made me realize I asked a silly question!!! Your help is still very much appreciated.

Sorry for the lack of details, I am using Korn Shell.