The way your tools work depends on the flavor of Unix that you use. The following should work on Linux, FreeBSD, NetBSD, OSX, etc.
#!/bin/sh sample="${1:-20120306131701}" if ! expr "$sample" : '[0-9]\{14\}$' >/dev/null; then echo "ERROR: unknown date format" >&2 exit 65 fi case $(uname -s) in *BSD|Darwin)
Note that this value is /bin/sh script for portability, so it does not take advantage of bash -isms that you can get used to on Linux, in particular [[ ... ]] and heretext, to read variables.
Oh, and I suppose you meant "exit value" when you said "return value". The return value will be the result of the function, but what I wrote above is a stand-alone script.
Please note that this may not understand future timestamps, and does not take into account the time zone. If this is important to you, you should think about it. :-) And the test is in your environment.
source share