mardi 8 décembre 2015

How can i produce error if no argument is given?

The object is to prompt the user with a question, (alphanumeric is to be entered), and if the user does not put anything in, it is supposed to produce an error stating "----> Entry is required", and loop back and prompt again, but i cannot figure it out...I took this working chunk from another program i made, any tips on how to format it to give an error to a null input?

    while [ true ]
    do

       echo -n "Enter course code: "
       read fact1
       chk_num=$( echo $fact1 | grep '^[0-9][0-9]*$' | wc -l )
       if [ "$chk_num" -eq 0 ]
          then echo
               echo "----> Entry is required"
               echo
          else break
      fi

    done

Aucun commentaire:

Enregistrer un commentaire