In a unix shell, how to get yesterday's date into a variable?

前端 未结 17 1440
谎友^
谎友^ 2020-12-04 21:51

I\'ve got a shell script which does the following to store the current day\'s date in a variable \'dt\':

date \"+%a %d/%m/%Y\" | read dt
echo ${dt}
         


        
17条回答
  •  一个人的身影
    2020-12-04 22:24

    If you are on a Mac or BSD or something else without the --date option, you can use:

    date -r `expr \`date +%s\` - 86400` '+%a %d/%m/%Y'
    

    Update: or perhaps...

    date -r $((`date +%s` - 86400)) '+%a %d/%m/%Y'
    

提交回复
热议问题