On 02/21/2014 03:26 PM, Eric Blake wrote: > 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 Oh, and be sure to use 'set -f' for the duration of your IFS splitting, to avoid globbing. -- 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