Hi, I'm very new to shell scripting and I'm sorry if this question is too dumb.
If it is ok, please link me to some beginner guides for questions like this one.
I want to check if the entered string is a number and has 4 digits.
I heard that I should use "regular expression" or something like that to accomplish this task, but I don't know how to use it.
Code:
echo -n "Input: "
read x
if [ $x == ${...err i dont know what to put here} ]
then echo "Valid"
else echo "Invalid"
fi
Any help is much appreciated!
============================================
* Edit:
I have found the answer for my question, hope it helps anyone who would like to search for this:
Code:
echo -n "Input: " ; read x
if [ $(echo "$x" | grep -c "^[0-9]\{4\}$") -eq 1 ] ; then
echo "Valid"
else
echo "Invalid"
fi
And this is what I have learned while I was trying to ask for this, on another forum:
http://www.unix.com/302306293-post8.html
I want to share it because I think it's nice and helpful. Please don't hate me for linking to other forums.
