I'm trying to use getops
in a function yet it doesn't seem to work:
#!/bin/bash
function main()
{
while getopts ":p:t:c:b:" o; do
case "${o}" in
p)
echo "GOt P"
p=$OPTARG
;;
t)
echo "GOt T"
t=$OPTARG
;;
c)
echo "GOt C"
c=$OPTARG
;;
b)
echo "GOt b"
b=$OPTARG
;;
*)
#usage
echo "Unknown Option"
return
;;
esac
done
echo $p
echo $t
echo $c
echo $b
}
main
And then running it like this:
$ ./bin/testArguments.sh -p . -t README.md -c 234 -b 1
I have tried making sure that optid are local yet this didn't work either. Anything else that might be wrong?