Hello,

On Fri, Aug 05, 2005 at 12:39:01AM -0700, OpenMacNews wrote:
> QUESTION:  how would i properly define/escape the esyscmd(arg)? i keep 
> staring at the silly thing and am in 'quote catch-22'  8-}

yes, it's difficult to get unmatched quotes.

The following should work:
define(`MY_IP_ADDR',
        esyscmd(dig @my.ns.domain.com machine.domain.com |
                grep machine.domain.com | grep -v DiG |
                grep -v ";"machine.domain.com | awk '{print $5}'))

It works because:
- the unmatched right quotes are in the outermost level
- the IP address contains no comma and no left quote.

But you see that this is not a general solution.  If youare not willing to
change the whole application and set eg. changequote([,]), you should
avoid using single quotes in your shell code.   You can use
        awk "{print \$5}"
or
        awk "{print $ 5}"

The latter alternative takes advantage of the fact that awk allows space
after the "$", while shell doesn't.  It also protects it from being
understood as m4 macro parameter, if you used this inside a macro.

Please note that in your example, the whole esyscmd call was quoted, thus
the pipe would be executed each time you call MY_IP_ADDR.
OTOH, the parameter to esyscmd was not quoted, which could cause problems
if the command contained comma.

To conclude, I suggest:

define(`MY_IP_ADDR',
       esyscmd(`dig @my.ns.domain.com machine.domain.com |
                grep machine.domain.com | grep -v DiG |
                grep -v ";"machine.domain.com | awk "{print $ 5}"'))

Have a nice day,
        Stepan Kasal


_______________________________________________
M4-discuss mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-discuss

Reply via email to