How to check if a variable contains a .

Hi
I am writing a bash script and would like to check is a variable contains a . or not
ex.
a=102 output ok
a=1.02 output not ok
Many thanks,

expr index "$a" .

Will check if the variable a contains a .

man expr

to learn more.

Thanks

Hi,

you could use the build-in test function of bash which supports regexp since version 3.0.

[[ $a =~ \\. ]] && echo not ok || echo ok

As the dot is a special character you have to escape it.

HTH Chris