Today's case is the decision to input to the user
#!/bin/sh # validint-validates integer input, allowing negative ints. function Validint {# Validate field. Then Test against Min value $ and/or # max value $ if they are supplied.
If They are not supplied, skip this tests. Number= "$"; Min= "$"; Max= "$" if [-Z $number]; Then echo "You didn ' t enter anything. Unacceptable. ">&2; Return 1 fi if ["${number%${number#?}}" = "-"];
Then # is a '-' sign? Testvalue= "${number#?}" # all but a character else testvalue= "$number" Fi nodigits= "$ (echo $testvalue | sed ' s/[[:d igit:]]//g ')" if [ ! -Z $nodigits]; Then echo "Invalid number format! Only digits, no commas, spaces, etc. ">&2 return 1 fi if [!-Z $min]; Then if ["$number"-lt "$min"]; Then echo "Your value is too small:smallest acceptable value are $min" >&2 return 1 fi fi if [!-Z $ma X]; Then if ["$number"-GT "$max"]; Then echo "Your value is too big:largest accePTable value is $max ">&2 return 1 fi fi return 0} if Validint" $ "" $ "; Then echo "That", is a valid integer value within your constraints "fi
Parsing script:
1) number= "$"; Min= "$"; max= "$" means 3 inputs from the user;
2) nodigits= "$ (echo $testvalue | sed ' s/[[:d igit:]]//g ')" Prepares all numbers for subsequent test user input
3 if Validint "$" "$" "$"; Then note "$" $ "$" to be quoted.
4) The TestValue variable is the number of test inputs to filter for negative numbers.
5 feel very thoughtful.