m4-discuss
[Top][All Lists]
Advanced

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

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


From: OpenMacNews
Subject: Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?
Date: Fri, 05 Aug 2005 08:55:15 -0700

hi stepan,

i think i'm getting the hang of m4 -- very cool! (in case you haven't guessed, i'm new to it ...)

so, one more step ...

first,

(1) prior advice works great!

since you already use awk, it's probably best to use printf instead of print.

And awk can also search for the right line.  If I understand the
format of the output of DiG correctly, it would be

    changequote([,])
    define([MY_IP_ADDR],
          esyscmd([dig @my.ns.domain.com machine.domain.com |
                awk 'index($ 0, "machine.domain.com") == 1 {
                        printf("%s", $ 5) }']))

This will work with any reasonable awk.

works perfectly!

fwiw (& hth others ...):

% which awk
   /usr/local/bin/awk
% awk --version
   GNU Awk 3.1.4
% uname -a
Darwin devbox 8.2.0 Darwin Kernel Version 8.2.0: Fri Jun 24 17:46:54 PDT 2005; root:xnu-792.2.4.obj~3/RELEASE_PPC Power Macintosh powerpc



(2) now, one FURTHER iteration -- confusion again:

in my next steps of building my httpd.conf.m4 template, i'm facing an issue w/ nesting of VARIABLES ...


now, i'd like to reference an earlier-defined variable INTERNAL to m4. in principle:

        changequote([,])
        define([MY_NS_NAME],         [ns.domain.com])
        define([MY_HOST_NAME],       [machine.domain.com])

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

but, with this, on processing, i get an error:

        dig: couldn't get address for 'MY_NS_NAME': not found

clearly, the var 'MY_NS_NAME' is not being passed ...


reading further @:

        http://www.gnu.org/software/m4/manual/m4.html#Indir

       which results in a call to the macro name, which is passed the rest of
       the arguments. This can be used to call macros with “illegal” names
       (define allows such names to be defined):
           define(`$$internal$macro', `Internal macro (name `$0')')
           =>
           $$internal$macro
           =>$$internal$macro
           indir(`$$internal$macro')
           =>Internal macro (name $$internal$macro)

, i guessed that 'indir' might be my solution with:

        changequote([,])
        define([$$MY_NS_NAME],         [ns.domain.com])
        define([$$MY_HOST_NAME],       [machine.domain.com])
        define([MY_IP_ADDR],
       esyscmd([dig @indir[$$MY_NS_NAME] indir[$$MY_HOST_NAME] |
       awk 'index($ 0, "indir[$$MY_HOST_NAME]") == 1 {
       printf("%s", $ 5) }']))

but this results in:

        dig: couldn't get address for 'indir[1914MY_NS_NAME]': not found

if indir IS my solution (is it?), then, again, i'm fairly sure i've got the "$" syntax screwed-up ...


cheers,

richard




reply via email to

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