commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
On CentOS at least, date returns a boolean for the common date string formats, including YYYY-MM-DD. In the sample output, you can see various invalid dates returning 0 whereas a simple regex check would return 1 for the invalid dates.
-d, --date=STRING display time described by STRING, not `now'
The version of date on OS X does not appear to have this same option.
There is 1 alternative - vote for the best!
Quick and easy way of validating a date format of yyyy-mm-dd and returning a boolean, the regex can easily be upgraded to handle "in betweens" for mm dd or to validate other types of strings, ex. ip address.
Boolean output could easily be piped into a condition for a more complete one-liner.
If you can do better, submit your command here.
You must be signed in to comment.