jeudi 26 février 2015

getopts passing value of declared parameter to function


I have function port.sh as stand alone script and i'm wondering if is possible to put this function in the same script where getopts is and pass value of OPT_B into function and get output of it?



OPT_B=B

while getopts :a FLAG; do
case $FLAG in
b) #set option "b"
OPT_B=$OPTARG
;;
esac
done

shift $((OPTIND-1))

!!-->> port $1 <<--!! -> OPT_B=$(port $1) ??

function port()
{
if [ "$1" = 'B' ]; then
set $1=8000
echo "declared value: $1"

elif [[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -ge 1 -a "$1" -le 10000 ]; then
echo "chosen value: $1"
else echo "chosen value $1 is not in '1 - 10000'"
fi
return 0;
}


Aucun commentaire:

Enregistrer un commentaire