sh - Parsing string for retrieving date in UNIX and freeBSD -
i have string in following format: yyyy-mm-dd
how can convert date on unix and freebsd? know is
date -d $var +'%y-%m-%d'
on gnu
and
date -jf $var +'%y-%m-%d'
on freebsd
but if script (in sh, not in bash) have work on both os? how can combine it?
because date command different kind of solution might if detect correct platform:
#!/bin/sh var='2014-03-15' platform='uknown' str="$(uname)" if [ "$str" == 'linux' ]; platform='linux' elif [ "$str" == 'freebsd' ]; platform='freebsd' fi
then according platform can do:
if [ "$platform" == 'linux' ]; date -d "$var" +'%y-%m-%d' elif [ "$platform" == 'freebsd' ]; date -jf "%y-%m-%d" "$var" +'%y-%m-%d' fi
also think missing format command:
date -jf $var +'%y-%m-%d'
i think should be:
date -jf "format" $var +'%y-%m-%d'
Comments
Post a Comment