Checking user input to a script
Hi all.
I am reasonably new to Linux and need some help with a script that I am writing. What I am struggling with is: The user is prompted to enter a 5 digit number. How would I go about evaluating that the input is valid? In another part of the script, the user is prompted for a string that consists of 4 alphas and 4 numerics, eg. abcd4321 Again, I am trying to do the same, as well as checking the case (either upper or lower) of the alphas. If someone could point me in the right direction, I would be very grateful. TIA If I have posted this in the wrong forum, then I do apologise. I am new here. :-) |
This can be done with simple if statements.
So you set your users input with the read statement. So... Code:
echo "Would you like to proceed? [Y/n]" `alnum' Letters and digits. `alpha' Letters. `blank' Horizontal whitespace. `cntrl' Control characters. `digit' Digits. `graph' Printable characters, not including space. `lower' Lowercase letters. `print' Printable characters, including space. `punct' Punctuation characters. `space' Horizontal or vertical whitespace. `upper' Uppercase letters. `xdigit' Hexadecimal digits. |
Quote:
Quote:
http://tldp.org/LDP/abs/html/abs-guide.html. EDIT: Kustom42 posted a great response while I was typing... |
http://tldp.org/LDP/Bash-Beginners-G...l/chap_07.html
Is also a great resource for this sort of stuff. Keep in mind the script I posted was just an excerpt from one of mine didnt want to write a new one so it doesn't specifically meet your needs but gives you an idea of what you need to do. |
Lol me and TB0ne both send you to the same link. Gotta love it.
|
Thank you for all the input.
I have got the first (numeric) checks working 100%. No just to tackle the second check, which is the one that I think I am going to struggle with, but that is for tomorrow. I am using bash, by the way. |
All times are GMT -5. The time now is 03:33 AM. |