Re: How to automatically replace date string with m4?

Eric Blake <[email protected]> Mon, 18 Jan 2016 07:58:53 -0700
Newsgroups gmane.comp.gnu.m4.general
Organization Red Hat, Inc.
Message-ID <[email protected]>
On 01/17/2016 06:28 PM, Jack J. Woehr wrote:
> Peng Yu wrote:
>> I can use coreutils' date to generate a date with a date string as
>> follows.
>> date -d yesterday
>> date -d tomorrow
>>
> Well, you can start with:
> 
>    esyscmd(date)
>    Sun, Jan 17, 2016  6:24:03 PM
> 
> ... and proceed from there

In particular, you could:

define(`YESTERDAY', `esyscmd(`date -d yesterday')')

although the resulting date output will be scanned for further macros;
if you want to guarantee that it will not be re-expanded, then your
syscmd usage also needs to output m4 quoting characters:

define(`YESTERDAY',
  `esyscmd(`printf "`"; date -d yesterday; printf "'"')')

Note that the above gets tricky thanks to mixing shell and m4 quoting
rules; you may want to consider using changequote() to pick something
that mixes nicer with shell (the way autoconf picked [] rather than `'
for that very reason).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc (application/pgp-signature, 604 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJWnP2tAAoJEKeha0olJ0NqoBwH/3MmQi/9Nrx0fpG8bnOR8upl
bMtXT0VwY7c1R7aC+JFam9HxOO5gs0KpCj6Z1DMfeLNIN8iZEZ6mzrso/jpBGsht
Z2mtzo7H5ZZKV1QY8nGka080aFHrBMUJgh5Za/cmjlvaVdxGf34XYDu1n18wLljV
yDEK9XF2bETMJrARp5zI66ComYok+2A1+zwZjyEDTozRdWBc6131ZQX7AJPp9sBl
LjU7pPJz1kcz2R8sWzrmX0AUZNr90F021KzGSYN4pqBk0tW+T6JQVgWoIA3TXTwu
j2p9RzX2dFWfHL54TDnwd6BkFDN2eV3wHzD/NfhWYAJ93dU1Xhe15o7QfsZLUxw=
=u2Ew
-----END PGP SIGNATURE-----