Issue
The following call:
date -d `echo 20150430+1 | bc`
gives: date: invalid date ‘20150431’
and I am trying to save that output to the variable f
without success:
f=`date -d \`echo "20150430+1" | bc\``
and
f=$(date -d $(echo 20150430+1 | bc))
They output an empty variable f
, what am I doing wrong?
Any hints are appreciated,
PS: bash - 5.0-6ubuntu1.2
Solution
You need to capture stderr for example by redirecting it to stdout:
$ f=`date -d 20150431 2>&1`
$ echo $f
$ date: invalid date ‘20150431’`
Answered By - Allan Wind Answer Checked By - Mary Flores (WPSolving Volunteer)