Reputation: 91
echo " write a number: "
read num
Today=`date`
aday=$(date -d '-($num) day' )
echo "$Today "
echo "$aday "
I want to find any day before today. For example in my code, the user write a number such as 3. And my program will estimate this day and print it. If I write (-1) ,I can find yesterday or If I write (-3) , ı will find 3 days ago. But when I write the number which is given by user , I didn't find the day bedore today. Can you help me at this point ?
Upvotes: 0
Views: 238
Reputation: 206
$num between '' won't be evaluated, you need to use "", ie:
$ foo=bar; echo " $foo"
bar
$ foo=bar; echo ' $foo'
$foo
So, for you example:
echo " write a number: "
read num
Today=`date`
aday=$(date -d "-$num day")
echo "$Today "
echo "$aday "
Upvotes: 1