If I run this command on OSX bash terminal:
date -jf '%F %TZ' -v+$((10**9))S -u "2011-04-25 00:00:00Z"
I get exactly what I want: Thu Jan 1 01:46:40 UTC 2043
but when I run:
./gigasecond.sh '2011-04-25'
I get:
2011-04-25 00:00:00Z
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
All gigabit.sh contains is:
#!/bin/bash
size=${#1}
DATE_SET_TO_MIDNIGHT="${1%Z} 00:00:00Z"
echo $DATE_SET_TO_MIDNIGHT
PARSE_DATE_AND_FORMAT=$(date -jf '%F %TZ' -v+$((10**9))S -u "$DATE_SET_TO_MIDNIGHT")
echo $PARSE_DATE_AND_FORMAT
What am I missing?
You need to quote $DATE_SET_TO_MIDNIGHT
, because it contains whitespace.
PARSE_DATE_AND_FORMAT=$(date '%F %TZ' -v+$((10**9))S -u "$DATE_SET_TO_MIDNIGHT")
Unless you have a very good reason not to, you should always quote parameter expansions.