[GRLUG] Bash glob

Jeff DeFouw mrj at plorb.com
Tue May 7 13:30:12 EDT 2013


On Tue, May 07, 2013 at 11:16:29AM -0500, L. V. Lammert wrote:
> Trying to ensure the parameter to a script matches:
> 
> 	YYYY-MM (e.g. 2013-06)
> 
> It would seem this would be the desired pattern:
> 
> if [[ ! $1 =~ '[0-9]{4}-[0-9]{2}' ]] ; then
>    echo '    Usage: backup YYYY-MM'
>    exit
> fi
> 
> However it will not match a valid YYYY-MM. Cluestick, anyone?

I didn't know bash had a regular expression operator.  Apparently you're 
not supposed to quote the pattern.  Anything between quotes is done as a 
literal string match.

-- 
Jeff DeFouw <mrj at plorb.com>


More information about the grlug mailing list