简体   繁体   中英

What does gdate mean in this shell script?

I need to maintain this shell script:

export DAYDAY=`gdate --date "30 days ago" +"%Y%m%d"` 
if [ -d $TMP/AA/$DAYDAY]; then
    rm -r $TMP/AA/$DAYDAY  
fi

But I can't run it because it can't find gdate ; this code is to clear the log directory that is exactly 30 days old.

On *nix systems other than Linux it's fairly common for the GNU flavor of utilities to be installed prefixed with a g (eg gmake , gtar , etc). In this case, it's likely this refers to the GNU flavor of the date command. So, since you are on Linux, just change it to date :

export DAYDAY=`date --date "30 days ago" +"%Y%m%d"` 
if [ -d $TMP/AA/$DAYDAY]; then
    rm -r $TMP/AA/$DAYDAY  
fi

It's G NU's date ; called gdate on BSD-related systems to differentiate it from their own date .


I work on Linux in a 90% Mac office and quite a few of my colleagues' scripts reference things like gsed and gdate . Where I couldn't fix this properly with a switch on $OSTYPE I eventually capitulated and did this:

sudo ln -s $(which date) /bin/gdate

This symlinks gdate to date .

This is quite safe because there should never be a gdate (or a gsed , gtar or gmake ), for the version installed on GNU/Linux is the GNU version, obviously.

You could also alias the command of course, but this carries over users and shells. It is in effect aliasing the whole program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM