Results 1 to 2 of 2
I'm a noob a bash scripting and want to write a script where the number of arguments varies.
Is there any easy way to do this?
The arguments will later ...
- 02-26-2011 #1Just Joined!
- Join Date
- Feb 2011
- Posts
- 1
Bash scripting: Arguments to script
I'm a noob a bash scripting and want to write a script where the number of arguments varies.
Is there any easy way to do this?
The arguments will later be used in the script and should have individual names (but that shouldn't be a problem).
Furthermore is there a simple way to count the number of arguments? I could of course make a for loop or something, but it would be great if there was an actual function.
Thank you!
- 02-27-2011 #2Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
A special variable $# always contains the number of arguments, passed to a script. So
would count them and display a result.Code:#!/bin/bash echo $#
You can access these arguments using $1, $2, $3, $4, etc. variables


Reply With Quote