Scenario. I have this code:
regexp="[^0-9A-Za-z]+"
while [[ $var =~ $regexp ]]
do
{
var=$(dialog --inputbox "File name (number and letters only): " 12 60 --stdout)
}
done
echo $var
Condition:
The variable var should not be set (is not set) before while statement;
Target:
Leave while statement only when the variable has alphanumeric values.
But if I try to run it don't work. It works if I set up variable var, e.g:
regexp="[^0-9A-Za-z]+"
var="_"
while [[ $var =~ $regexp ]]
do
{
...
Now, how to run that code without set up variable var?
varbeforewhileor place thiswhileintowhile true; ... done. The regex to match 1 or more alphanumeric characters is[0-9A-Za-z]+.