[Top][All Lists]

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

Re: Use pipe and sed in

From: Gary V. Vaughan
Subject: Re: Use pipe and sed in
Date: Thu, 10 Feb 2011 23:43:05 +0700

On 10 Feb 2011, at 10:39, Lyre <address@hidden> wrote:

> I tried to exact an option from php-config using:
> php-config --configure-options | sed -n
> 's|.*--with-config-file-scan-dir=\([^ ]*\).*|\1|p'
> It works on shell, and outputs "/etc/php5/conf.d/" on opensuse.
> And I tired it in, as following:
> PHPINC=`php-config --includes`
> PHPCDIR=`php-config --configure-options | sed -n
> 's|.*--with-config-file-scan-dir=\([^ ]*\).*|\1|p'`
> After subsitution in Makefile, the PHPCDIR is empty´╝î meanwhile PHPINC get
> the correct result.
> What' the correct way to use it?

Autoconf turns your specification in a configure shell script by 
it through GNU M4, with the M4 quote characters set to [ and ]. So M4 thinks you
are telling it not to expand [^ ] in the sed match expression, and after doing 
that, it
then throws those quote marks away.

If you search for the expanded text in the configure script, you'll see 
like this:

    PHPCDIR=`php-config --configure-options | sed -n \
      's|.*--with-config-file-scan-dir=\(^ *\).*|\1|p'`

Note the missing brackets, which means the sed match expression no longer
works as expected.

A rule of thumb is that you need to M4 quote sections of raw shell code in the file if you don't want them to remain unmolested in the generated
configure script. Things get a little more complicated if you are writing 
macros, but in this case doubling up the [ and ] in should work:

    PHPCDIR=`php-config --configure-options | sed -n \
      's|.*--with-config-file-scan-dir=\([[^ ]]*\).*|\1|p'`

And you can search the generated configure script for PHPCDIR to check!

There are some other M4 syntaxes you need to watch out for too, but I'm pretty
sure they're all covered by the info manuals.

Gary V. Vaughan (address@hidden)

reply via email to

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