Bash scripting question

David A. Bandel david
Mon May 17 11:47:50 PDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 26 May 2003 21:45:32 -0700
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

assuming you?re using BASH

try:

for i in $@; do <whatever>; done

Ciao,

David A. Bandel
- -- 
Focus on the dream, not the competition.
		Nemesis Racing Team motto
GPG key autoresponder:  mailto:david_key at pananix.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+00eMj31PLQNUbV4RAvrhAJ4hgc1hnfJbLyqBRhNfnJoqEwaa+QCglB9V
jJ+DZvbK1l6bmuXS2+dyO0A=
=ToxG
-----END PGP SIGNATURE-----



More information about the Linux-users mailing list