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: Dale Visser
Subject: RE: Recommended way to truncate a shell variable value in autoconf
Date: Fri, 21 Feb 2014 22:37:57 -0500

David:

I looked at the docs and see what you mean. Amazing how portability concerns  
affect even the lowly echo command. I will try replacing

echo "$X"

with

AS_ECHO([$X]).

Thank you!
Dale

Sent from my Windows Phone
________________________________
From: David A. Wheeler<mailto:address@hidden>
Sent: ‎2/‎21/‎2014 9:55 PM
To: autoconf<mailto:address@hidden>
Subject: RE: Recommended way to truncate a shell variable value in autoconf

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

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


reply via email to

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