[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: |
Fri, 5 Aug 2005 10:28:24 +0200 |
User-agent: |
Mutt/1.4.1i |
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
- confused by m4 esyscmd expansion ... how to 'escape' nested quotes?, OpenMacNews, 2005/08/05
- Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?,
Stepan Kasal <=
- Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?, OpenMacNews, 2005/08/05
- Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?, Stepan Kasal, 2005/08/05
- Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?, OpenMacNews, 2005/08/05
- Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?, Stepan Kasal, 2005/08/06
- Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?, OpenMacNews, 2005/08/06
- Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?, Stepan Kasal, 2005/08/07
- Re: confused by m4 esyscmd expansion ... how to 'escape' nested quotes?, OpenMacNews, 2005/08/07