I'm trying to create a loop that will prompt the user for 15 values, not forcing them to enter all 15. If the user enters through one or more of the prompts the null value needs to be converted to 0, otherwise set the parameter = to the value entered:
ex.
Please enter file no #1: 17920
Please enter file No #2: 11100
Please enter file No #3:
....
Please enter file No #15:
I will then be taking these values and passing all 15 values onto another script or program.
Here's what I have so far:
counter=1
while [ $counter -gt 0 -a $counter -lt 16 ]
do
if [ $counter -gt 0 ] ; then
echo " File No #$counter: \c"
read file_no
case $file_no$counter in
'') file_no_$counter=`echo 0`;;
*) file_no_$counter=`echo $file_no$counter`;;
esac
fi
counter=`expr $counter + 1`
done
I'll take your word that this is for work. But I'm not sure of what you exactly want. Nor do I know what shell you're using. You are using stuff present in the old bourne shell so I'll stick with that and take a guess at what you want: