Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to set and accept default value

Status
Not open for further replies.

gotchausa

Programmer
Jan 24, 2002
64
CA
Hi,

I have a script which asks a question at the beg. of the script. THe user has to enter a value greater or equal to one. I want to make 1 as the default no. so that user only has to hit the ENTER key to enter 1 - instead of having to enter the actual no 1. Is there a way of doing this?

Thanx.
 
Hi,

With Ksh, you can do to set the default value to 1 :


echo "Enter option : \c"
read OPTION
: ${OPTION:=1}

Jean Pierre.
 
Great! Thanks. It works if I follow your example but I have something like this ...

trap 'print "\nYou did not enter a valid number. Try again .."' ERR

# User input must be integer
typeset -i REPLY

# Now get user input and loop thru till valid response received
while true
do
echo "\nEnter the number of tapes you will be restoring"
echo "for this restore operation: \c"

read REPLY 2> /dev/null

if (( $? == 0 ))
then
# OK, so integer has been entered but make sure it is more or equal to 1
while (( $REPLY < 1 ))
do
echo &quot;\nYou must enter a number greater or equal to 1: \c&quot;
read REPLY 2> /dev/null
done

break
fi
done

# Unset pseudo trap for ERR
trap - ERR


When I follow your example, my script just accepts any and all input and then cont. which is not what I want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top