Problem in bin/sh stripping the * character through ${expansion%}

Doug Barton dougb at FreeBSD.org
Thu Aug 6 18:15:20 UTC 2009


Howdy,

I came across this problem during a recent portmaster update. When
trying to strip off the * character using variable expansion in bin/sh
it doesn't work. Other "special" characters do work if they are
properly escaped.

The attached mini-script clearly shows the problem:

$ sh sh-strip-problem
var before stripping: foo\*
var after stripping: foo\*

var before stripping: foo\$
var after stripping: foo\

In contrast, bash does the right thing:

bash sh-strip-problem
var before stripping: foo\*
var after stripping: foo\

var before stripping: foo\$
var after stripping: foo\

Should I go ahead and file a PR on this?


Doug

-- 

    This .signature sanitized for your protection

-------------- next part --------------
var='foo\*'
echo "var before stripping: $var"
var=${var%\*}
echo "var after stripping: $var"
echo ''
var='foo\$'
echo "var before stripping: $var"
var=${var%\$}
echo "var after stripping: $var"

exit 0


More information about the freebsd-hackers mailing list