Hi, guys.
In Linux Shell script, how can I check a string whether meets some conditions.
e.g.:
If a string str must start with a underscore or a alphabet, and it must contains at least one lowercase, one uppercase, one numeric and one punctuation, and its length must be more than 8 characters long and less than 16 characters long, how should I check it?
I can just use the command grep and my command like this:
a='aBc3o!9203'
echo "$a" | grep '^[_a-Z]' | grep '[A-Z]' | grep '[a-z]' | grep '[0-9]' | grep '\W'
It just works when determining whether the correct characters included in the string, and it doesn't include the length check. However, it's so wired and so complex and lengthy.
Does anyone have better ideas?
Thanks!
But you're right, grep | grep | grep | grep isn't terribly efficient. You could do it in several case statements and use ${