Bash shell: How to check for specific date format?
问题 I have a Bash shell script which checks to see if a shell variable contains a number: if ! [[ "$step" =~ ^[0-9]+$ ]] then exec >&2; echo "error: $step is Not a step number."; exit 1 fi Now I need to do a similar check to see if a variable contains the date in the required format which is YYYY-MM-DD (example: today is 2013-05-13) with the dashes. How can this be done with a regular expression in Bash shell or do I need an external program to do this? 回答1: regex is not the right tool to do the