Validating user input in shell script No credit no credit card info to for sex viewing
In order to avoid this common mistake I often have my shell scripts prompt me for a yes or no answer before they proceed.
The function described here is for doing that: asking a question and validating the answer.
The main function checks the arguments then loops until it receives a valid answer.
Note that if a timeout was specified and any answer (valid or invalid) is entered the timeout is turned off.
You were taught that your program should nicely tell the user what was wrong and how to fix the problem.
You may have ended up writing thousands of lines of code to cover every possible scenario where the user could mess up the input.
The answer is converted to lower case so any combination of case is accepted.
# To test whether an entered value is a valid floating-point number, we # need to split the value at the decimal point.As you saw in Script #2, validating integer input seems like a breeze until you want to ensure that negative values are acceptable too.