Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 06 Aug 2009 11:15:12 -0700
From:      Doug Barton <dougb@FreeBSD.org>
To:        freebsd-hackers@freebsd.org
Subject:   Problem in bin/sh stripping the * character through ${expansion%}
Message-ID:  <4A7B1DB0.1040602@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------000003020807060309050608
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

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


--------------000003020807060309050608
Content-Type: text/plain;
 name="sh-strip-problem"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="sh-strip-problem"

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

--------------000003020807060309050608--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4A7B1DB0.1040602>