Core iTOps Tube

Thursday, 26 April 2012

I it possible to prompt for input if not given on command line?

I have a script built that takes the standard inputs $1 $2 $3 after the name and parses some data.




Code:




hexsite=`echo "obase=16;$1"|bc`

hexfix=$(printf "%.3X" 0x$hexsite)

if [ "$2" == "1x" ] || [ "$2" == "1X" ];then

type=33

elif [ "$2" == "ev" ] || [ "$2" == "EV" ];then

type=59

elif [ "$2" == "both" ];then

type=99

else type=00

fi

cat /directory/*.2012$3*|


I am looking for a way to prompt for the input if someone does not include it in the command line. I can get the input via 'read' statements:




Code:




echo "Input site number: "

read decsite

hexsite=`echo "obase=16;$decsite"|bc`

hexfix=$(printf "%.3X" 0x$hexsite)

echo "Input type: "

read rawtype

if [ "$rawtype" == "1x" ] || [ "$rawtype" == "1X" ];then

type=33

elif [ "$rawtype" == "ev" ] || [ "$rawtype" == "EV" ];then

type=59

elif [ "$rawtype" == "both" ];then

type=99

else type=00

fi

echo "Input date: "

read daterange

cat /directory/*.2012$daterange*|


But I would like to work both ways instead of one or the other depending on what the user does.




No comments:

Post a Comment