Re: Recommended way to truncate a shell variable value in autoconf

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

 



On 02/21/2014 03:08 PM, Dale Visser wrote:
> I have a macro argument that I would like to place in a shell variable, but with a catch. I want to truncate it at the first space or comma. I have code that works for me (in Ubuntu), like this:
> 
>     my_var="$1"
>     my_var=${my_var%%\ *}
>     my_var=${my_var%%,*}
> 
> However, I read at https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Shell-Substitutions.html#Shell-Substitutions that this construct "[does] not work with many traditional shells, e.g., Solaris 10 /bin/sh."

What we NEED to do is finally bite the bullet to require XSI parameter
expansion of any shell that runs configure (we've already had snoop code
in the wild to prove that such a shell can be found, and no one has
submitted bug reports from any museum machine where the snoop has
triggered - even Solaris, with its ancient /bin/sh, has a better shell
that is always installed and easy enough to find).  Then we could
simplify quite a bit of configure by actually using these substitutions.

> 
> I am at a loss to figure out an acceptable "autoconf portable way" to accomplish this. I suspect some usage of m4_split (https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Text-processing-Macros.html#index-m4_005fsplit-1486) could be the answer, but haven't been able to figure out how to make it work correctly.

If you guarantee that your shell is capable (right now, that could be
done by using the undocumented _AS_DETECT_REQUIRED macro), then your way
is portable.  Until then, the only portable fallback to this particular
problem is the use of 'expr' pattern matching and/or sed scripts.  :(

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
https://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux