So, I'm running a script with a couple of subroutines, one of which takes arguments using getopts. The first time i call the subroutine everything works as expected, the second time I call it none of the arguments change. Here's a small section of code that shows this behavior.
#!/bin/sh
#Testing getopts
Sbrt()
{
while getopts ":a:b:" opt; do
case $opt in
a ) aarg="$OPTARG";;
b ) barg="$OPTARG";;
\?) echo "usage" ;;
esac
done
shift $(($OPTIND - 1))
echo $aarg $barg
}
Sbrt -a A1 -b B1
Sbrt -a A2 -b B2
Output:
A1 B1
A1 B1
So how can I call the subroutine again and have it update the arguments (aside from making the subroutine a separate script, of course). I searched, if anyone knows of any threads pertaining to this let me know and i'll clear this out of here.