At Fri, 05 Dec 2025 08:51:20 +0700, Robert Elz <kre%munnari.OZ.AU@localhost> wrote:
Subject: Re: use of "build.sh -B BUILDID".... with patch and more questions
>
> I haven't really been following this, I'd never heard of BUILDID
> before, but:
>
> | + # remove any leading (and trailing) whitespace
> | + val=${val##*[[:blank:]]}
> | + val=${val%%*[[:blank:]]}
>
> Those don't do what you want, the first would remove everything up
> to, and including, the rightmost blank in the variable's value.
Oops! Sigh, I had only tested those with ksh, but not even properly
there it seems.
I think though I've settled on just letting the shell do it while
parsing a command line, i.e.:
var=$(echo $var)
That gets rid of extraneous duplicate whitespace between words too.
In a function taking a varname argument:
trim ()
{
local _var _val
if [ $# -ne 1 -o -z "${1}" ] ; then
echo "Usage: trim varname" >&2
return 2
fi
_var="$1"
eval _val=\"\${${_var}}\"
eval ${_var}=\$\(echo \${_val}\)
unset _var _val
}
--
Greg A. Woods <gwoods%acm.org@localhost>
Kelowna, BC +1 250 762-7675 RoboHack <woods%robohack.ca@localhost>
Planix, Inc. <woods%planix.com@localhost> Avoncote Farms <woods%avoncote.ca@localhost>
Attachment:
pgp9KVuwfr4kV.pgp
Description: OpenPGP Digital Signature