m4-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How substitute a name as part of a string


From: Eric Blake
Subject: Re: How substitute a name as part of a string
Date: Wed, 13 May 2015 10:04:43 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]