autoconf
[Top][All Lists]
Advanced

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

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


From: Eric Blake
Subject: Re: Recommended way to truncate a shell variable value in autoconf
Date: Fri, 21 Feb 2014 15:26:10 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 02/21/2014 03:23 PM, Eric Blake wrote:
> 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%%,*}
>>

> 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.  :(

Or mess with IFS splitting:

my_var=$1
IFS=' ,'
set dummy $my_var
shift
IFS=' ''        ''
'
my_var=$1

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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