[GRLUG] Bash regex

L. V. Lammert lvl at omnitec.net
Tue May 7 14:21:35 EDT 2013


> See ^^$ info '(bash)Conditional Constructs'^^ which, in explaining the
> regex ^^=~^^ operator, says ^^Any part of the pattern may be quoted to
> force it to be matched as a string.^^ Your expression works after
> removing the single quotes.
>
I had tried single, double, as well as no quotes, .. none would match the
YYYY-MM string when properly formatted.

I ended up with:

if [[ ! $1 =~ [0-9][0-9][0-9][0-9]-[0-9][0-9] ]] ; then
   echo '    Usage: backup YYYY-MM'
   exit
fi

I believe the main problem was the missing 'number' modifier usable in
bash, so I had to explictly repeat the digits.

	Thanks!

	Lee


More information about the grlug mailing list