Issue
I am trying to convert the date format in UNIX, the format is getting converted but unable to assign it to a variable.
DATE=20200520
A=date -d"$DATE" +%Y\-%m\-%d
-bash: -d20200501: command not found
date -d"$DATE" +%Y\-%m\-%d
This is properly working, but when assigned to variable it's failing.
I tried assigning using A = $(date -d"$DATE" +%Y\-%m\-%d)
symbol as well, still it's not working.
Solution
We have to use $ symbol when assigning the result of another command to a variable.
A=$(date -d"$DATE" +%Y\-%m\-%d)
There is a space in between A and = symbol and $ symbol, that is the reason it failed while using $ symbol
Answered By - Jim Macaulay Answer Checked By - David Marino (WPSolving Volunteer)