Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to initialise a variable with yesterday's date in a specific format . ex---if today is 15 Feb, then variable should be-- var=Feb 14

date -d"-1day" +"%b %d" is not working. I don't know whether the syntax is incorrect or why else it is not working.

What is the correct way to use it?

share|improve this question

1 Answer 1

Put $( ) around the command when assigning, eg:

#!/bin/bash

hi=$(date -d'-1day' +'%b %d')

echo "$hi"

Works.

Updated as per geirha's comment.

share|improve this answer
    
it does not work. it says date: --d : illegeal option. i am using putty –  user10631 Feb 15 '11 at 11:00
    
What is the exact way you are using it then? (Update your original post) –  Ward Muylaert Feb 15 '11 at 11:04
    
var=$(date -d"-1day" +"%b %d"); echo $var –  user10631 Feb 15 '11 at 11:06
    
That usage works fine for me. –  Ward Muylaert Feb 15 '11 at 11:08
    
but it shows the message-> date: --d : illegeal option...any other way of doing it? –  user10631 Feb 15 '11 at 11:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.