Here is my short script:
#!/bin/bash
user=""
secret=""
pkgname=""
while getopts ":p:s:u:" opt; do
case ${opt} in
p )
pkgname=$OPTARG
echo "p=$pkgname"
;;
s )
secret=$OPTARG
echo "s=$secret"
;;
u )
user=$OPTARG
echo "u=$user"
;;
\? )
usage
exit 1
;;
:)
echo "Option -$OPTARG requires an argument."
usage
exit 1
esac
done
When I run it using following command:
./script.sh -u 'uuuu' -s 'aaaa' -p pkg.rpm
Output:
u=uuuu
s=aaaa -p
While I expect it to be
u=uuuu
s=aaaa
p=pkg.rpm
I tried doing multiple combinations of the parameters by changing the sequence as well but not able to solve it. Why the value for 's' is incorrect?