25 lines
370 B
Bash
25 lines
370 B
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
#
|
||
|
|
# Building a regular expression to match a simple-format ISO8601 date
|
||
|
|
#
|
||
|
|
|
||
|
|
re='^[0-9]{4}(-[0-9]{2}){2}$'
|
||
|
|
|
||
|
|
#
|
||
|
|
# The date is expected as the only argument
|
||
|
|
#
|
||
|
|
if [[ $# -ne 1 ]]; then
|
||
|
|
echo "Usage: $0 ISO8601_date"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
#
|
||
|
|
# Validate against the regex
|
||
|
|
#
|
||
|
|
if [[ $1 =~ $re ]]; then
|
||
|
|
echo "$1 is a valid date"
|
||
|
|
else
|
||
|
|
echo "$1 is not a valid date"
|
||
|
|
fi
|