Yesterday's date without changing anything and in one cmd line ?

I have seen references in the forum about getting yesterday's date but it is either by changing something in the system (date, time zone, ...) or with more then one line of script cmds.

How can I get yesterday's date without changing anything in the system and in one single command line ?

Only with GNU date, part of coreutils. Otherwise you'll have to write a lower level module - C, perl, python. You may even be able to cram it into one line of perl for example - so you can call it directly. Most of our date stuff uses homegrown perl modules.

ie:

/usr/bin/local/lbin/yesterday.pl

which is about 8 lines of perl.

One-liner, w line continuation to make it more readable...

#  Today minus 1... (um, yesterday...?) 
   pl_today_1=`perl -e '\
      $y= time - (86400 * $ARGV[0]); \
      printf "%04d%02d%02d\n", (localtime($y))[5] + 1900 ,(localtime($y))[4] + 1 ,(localtime($y))[3] ; ' 1 ` 

You can manipulate the TZ setting for that single command. For example (assuming your TZ is GMT):

# echo $TZ
GMT
# date
Sun May 24 18:48:24 GMT 2009
# print - $(TZ=GMT+24; date)
Sat May 23 18:48:51 GMT 2009
# date
Sun May 24 18:48:59 GMT 2009

In the last line you see that the systems date is unchanged, the manipulated TZ-setting was in effect for the one line above only.

I hope this helps.

bakunin

Changing $TZ in the above example is local to your instance of shell. It does not affect other users of the computer. Unix and Linux allow individual users to operate in different timezones.