I’m kind of new in bash and I have a problem for which I’m unable to find solution anywhere on the internet.
Before I do something like trying to program it by myself, I would like to see what is the standard way of dealing with situations like this.
Basicaly I would like to capture getopts to array…
I’m not sure if I’m clear enough so let’s try to take a look at this PHP example:
http://www.test.com/index.php?a=1&b=2
<?php
function getParams() {
return $_GET[];
}
?>
This is what I want for like:
myscript -a 1 -b 2
So far, each and every mention of getopts that i have found was implicating that I need to know exactly what I’m trying to get like:
while getopts a:b: option
do
case "${option}"
in
a) a=${OPTARG};;
b) b=${OPTARG};;
esac
done
Is there a way in which I could have associative array of all arguments passed to the script no matter what those options are so I can always do something like this:
OPTS = get_params
echo $OPTS[@]
And then I could do some validation of my own etc…
Once again sorry if I’m missing something obvious, I’m really new to bash and I would really appreciate any help or guidance where to start.
Thank you very much in advance.
You can go along these lines:
Call this script
test_argsandchmod +x test_args. Then (illustrating the side effects of this oversimplified method):