I want to check if a variable has a valid year using a regular expression. Reading the bash manual I understand I could use the operator =~
Looking at the example below, I would expect to see ‘not OK’ but I see ‘OK’. What am I doing wrong?
i='test' if [ $i=~'200[78]' ] then echo 'OK' else echo 'not OK' fi
It was changed between 3.1 and 3.2:
So use it without the quotes thus: