Re: How substitute a name as part of a string
Eric Blake <[email protected]> Wed, 13 May 2015 10:04:43 -0600
| Newsgroups | gmane.comp.gnu.m4.general |
|---|---|
| Organization | Red Hat, Inc. |
| Message-ID | <[email protected]> |
On 05/13/2015 09:24 AM, Peng Yu wrote: > Hi > > The following code works. > > echo AUTHOR YEAR | m4 -D AUTHOR=Shakespeare -D YEAR=1587 > > But if I not space between AUTHORYEAR, how I should call m4 to do it? Thanks. $ echo "AUTHOR\`'YEAR" | m4 -D AUTHOR=Shakespeare -D YEAR=1587 Shakespeare1587 That is, any time you want to guarantee that the parser sees the end of one macro name, insert a quoted empty string to call out the start of the next string. Or, you can define the macro itself to end with an empty quoted string, at which point it may be easier to call the macro with 1 (empty) argument instead of with 0 arguments: $ echo "AUTHOR()YEAR" | m4 -D AUTHOR='Shakespeare`'\' -D YEAR=1587 Shakespeare1587 By the way, using m4 from the shell like this is rather difficult, due to the pains of quoting ` and ' correctly; you may want to use m4 with changequote done fairly early so that the rest of your scripting can use quoting more convenient for the shell. -- 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/ iQEcBAEBCAAGBQJVU3YcAAoJEKeha0olJ0NqbJEIAKGyqMd4ua6ZD3VF/Mr0pnWL R0oF5V9Kbx0Zv15g62htdQLekvyh45QcjNUufpzyPvLiHYXxT9MVhaulOtNHtXQS u+97MZvhnmMs54I3+qx/uWNB14CNi8ReP+yJQno5OTfV79+Mq0nk82ZdGJdG4c5i Bsh2eJlQLNHtXRE60ebiHNdjowE1AZqo1+598O5yONNGbE55LqRPndDcnuzMhlb5 pFp3eGou/VlRMbYP4ITB47Z+rsvHBGWe9o63Qd4lj+T9tZRIzoIiDQDbtCGhhBOS +i0JpF/n9geoXq7fLQxiBr9h3j5jXa3qw3aw9hgaQT5Kty/eidkNE+7Fkzxc3pU= =ee7h -----END PGP SIGNATURE-----