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

前端 未结 17 1437
谎友^
谎友^ 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:38

    If your HP-UX installation has Tcl installed, you might find it's date arithmetic very readable (unfortunately the Tcl shell does not have a nice "-e" option like perl):

    dt=$(echo 'puts [clock format [clock scan yesterday] -format "%a %d/%m/%Y"]' | tclsh)
    echo "yesterday was $dt"
    

    This will handle all the daylight savings bother.

提交回复
热议问题