[Top][All Lists]

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

Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?

From: Stepan Kasal
Subject: Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?
Date: Sat, 6 Aug 2005 17:56:27 +0200
User-agent: Mutt/1.4.1i


On Fri, Aug 05, 2005 at 08:55:15AM -0700, OpenMacNews wrote:
>       define([MY_IP_ADDR],
>        esyscmd([dig @MY_NS_NAME MY_HOST_NAME |
>        awk 'index($ 0, "MY_HOST_NAME") == 1 {
>        printf("%s", $ 5) }']))

A few examples:

1) esyscmd([dig @MY_NS_NAME MY_HOST_NAME])

esyscmd gets the string "dig @MY_NS_NAME MY_HOST_NAME", which it executes.

2) esyscmd(dig @MY_NS_NAME MY_HOST_NAME)

esyscmd get's the string "dig @ns.domain.com machine.domain.com".

So it seems that esyscmd should have the parameter without quotes.
But that wouldn't work, esyscmd would think it has three parameters:
        dig @MY_NS_NAME MY_HOST_NAME |  awk 'index($ 0
        "MY_HOST_NAME") == 1 { printf("%s"
        $ 5) }'
because m4 would interpret the commas in awk code.

The best solution is to quote the parameter, but "interrupt" the quote
for each macro; the rest od the command would be literal:

3) esyscmd([dig @]MY_NS_NAME[ ]MY_HOST_NAME[])

Or, if we were less strict:

4) esyscmd([dig @]MY_NS_NAME MY_HOST_NAME)

In both these examples, esyscmd gets the same parameter as in 2).

Back to your problem:

          esyscmd([dig @]MY_NS_NAME MY_HOST_NAME[ |
          awk 'index($ 0, "]MY_HOST_NAME[") == 1 {
          printf("%s", $ 5) }']))

Hope this explains it.

... and no, indir has nothing to do with this.

Does it make sense now?  (If yes, perhaps you could contribute to the
GNU m4 documentation, so that future readers don't go through the same
confusion.  It's difficult for the authors of the documentation to
understand how the text will be seen by newcomers' eyes...)

Have a nice day,
        Stepan Kasal

reply via email to

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