Hello everyone, I'm trying the best way to implement a check on a variable ... in particular I need to assess the content of characters [a-zA-Z] and numbers [0-9], I tried on various manuals bash scripting but I could not figure out how to do ... any help?
VAR="$@"
if [ -z "${VAR//[a-zA-Z0-9]}" ]; then
echo "VAR has only a to z, A to Z and 0 to 9!"
else
echo "VAR has non-alpha-numeric!"
fi
./Test abc
VAR has only a to z, A to Z and 0 to 9!
./Test 123abc
VAR has only a to z, A to Z and 0 to 9!
./Test 123+abc
VAR has non-alpha-numeric!
./Test !abc
VAR has non-alpha-numeric!
./Test 123!
VAR has non-alpha-numeric!
excuse me...
I think I have solved this way:
while ! [ -z "${VMC_NAME//[a-zA-Z0-9]}" ] || [ -z $VMC_NAME ]
do
echo ""
echo "Error! Enter a valid value or only alphanumeric characters:"
echo ""
read VMC_NAME
done
do you think? If I enter strings containing characters not Alphanumeric or blank left for me in heaven until I enter an appropriate value, right?