[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Recommended way to truncate a shell variable value in autoconf
From: |
David A. Wheeler |
Subject: |
RE: Recommended way to truncate a shell variable value in autoconf |
Date: |
Fri, 21 Feb 2014 21:54:52 -0500 (EST) |
Eric Blake said:
> .... Just go with:
> X=`echo "$X" | sed 's/[, ].*//'`
The "sed" is nice and clear.
However, that "echo" will probably cause trouble if $X starts with "-" or has
other characters in it.
I presume in this case that $X will *usually* start with "-", so you REALLY
don't want to use echo directly.
Unless $X can *only* contain alphanumerics, I suggest replacing echo "$X" with:
printf '%s\n' "$X"
An alternative would be to use AS_ECHO.
Dale Visser, you might want to look here:
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Portable-Shell.html
and especially:
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Limitations-of-Builtins.html
--- David A. Wheeler