As Benoit stated, the simplest solution is to pass the commandline arguments to the function as function arguments with $@
, then you can reference them in exactly the same way as outside the function. You'll actually be referencing the values passed to the function that just happen to have the same value as the commandline arguments, keep that in mind.
Note that this pretty much precludes you from passing any other arguments to the function, unless you know exactly how many arguments will be passed at the command line (unlikely as that is up to the user and isn't bound by your constraints)
i.e.
function fname {
# do something with $1 $2 $3...$n #
}
# $@ represents all the arguments passed at the command line #
fname $@
A better way is to pass only the arguments you know you will be using, that way you can use them in the function AND also pass other parameters from within your code if you wish
i.e.
function fname {
# do something with $1 $count $2 and $3 #
}
count=1
fname $1 $count $2 $3