Regular expression to control date format
Le
titof92

Hi,
I'm running a script sh, with a date formatted as "YYYYMMDD", as
argument (example : ./my_prog.sh 20111216
In my script, I just would like to test if the user specified an
argument respecting the folowing rules :
- 8 characters long
- constituted only by numbers
I tried to write this :
if [[$1 =~ /^[2][0][1-2][0-9][0-1][0-9][0-3][0-9]$/ ]]
then
..
fi
But it does not work;
Any suggestion ?
Thanks,
Christophe
I'm running a script sh, with a date formatted as "YYYYMMDD", as
argument (example : ./my_prog.sh 20111216
In my script, I just would like to test if the user specified an
argument respecting the folowing rules :
- 8 characters long
- constituted only by numbers
I tried to write this :
if [[$1 =~ /^[2][0][1-2][0-9][0-1][0-9][0-3][0-9]$/ ]]
then
..
fi
But it does not work;
Any suggestion ?
Thanks,
Christophe
[...]
Tu peux parler francais ici, tu sais.
case $1 in
(20[12][0-9][01][0-9][0-3][0-9]) ...
esac
--
Stephane
Super, merci beaucoup. Cela fonctionne bien.
Désolé, je pensais poster sur le forum comp.unix.shell... c'est
pourquoi mon message était en anglais... ;-)