Bash scripting question

Brad De Vries devriesbj
Mon May 17 11:47:51 PDT 2004


--- David Aikema <dhaikema at sfu.ca> wrote:
> I'm trying to loop through all of the command line
> parameters passed to 
> a bash script.
> 
> I know that $# is the total number of command line
> options passed 
> (well, $#+1 if you include $0, the name of the
> script) and that the 
> individual parameters can be access as $0, $1, $2,
> and so on.
> 
> How can I loop through all of the given parameters
> though?
> 
> for ((NUM=1; NUM <= $#; NUM++))
> do
> 	# what?
> 	#how can I access parameter # NUM?
> done
> 
> David Aikema

You could try:
---------
TOTCNT=$#
for ((NUM=1; NUM <= $TOTCNT; NUM++))
do
  echo "$NUM: $1"
  shift
done
---------

Brad.

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


More information about the Linux-users mailing list