问题
I am using X86 SOLARIS 10 and need the following bash script to get yesterday's date.
#!/usr/local/bin/bash
#ds=`date '+%Y%m%d' -d "+2 days"`
ds=`GMT+24 date +%Y%m%d`
#ds=`date --date yesterday +%Y%m%d`
echo $ds
Getting an error "GMT+24: command not found". Also, tried the methods that are commented without success. Any suggestion
回答1:
You can't do much date arithmetic with Solaris's own date
command. As others have pointed out you'll need GNU date.
See this link, which includes information on getting GNU date (part of GNU coreutils package) on Solaris. Make it a rule to always deploy the minimal GNU tools on your Solaris servers (see link). Make it part of your company's default install. Then you won't get into these issues. Or move to more recent Solaris(*) where GNU date is installed by default.
*) Solaris 10 is getting fairly old now that we're in Dec 2014.
来源:https://stackoverflow.com/questions/27258707/solaris-10-date-arithmetic