| Summary: | /bin/sh's hangling of some characters is wrong - loss of data | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Eugene Grosbein <ports> |
| Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 4.4-STABLE | ||
| Hardware: | Any | ||
| OS: | Any | ||
|
Description
Eugene Grosbein
2001-10-30 05:40:00 UTC
Le 2001-11-06, Eugene Grosbein écrivait : > #!/bin/sh > string=`printf "\21"` > echo $string | hd > Replace 21 with 201 and rerun. You see: > 00000000 0a |.| > 00000001 Can't reproduce here for the value \201, but for the other values you mention it looks like perfectly normal and expected behaviour from sh(1). It is not surprising at all that some characters "disappear" here: since $string appears unquoted, any character which is whitespace w.r.t. shell parsing rules won't be passed to echo. Try to quote your string: echo "$string" | hd In your other example, you use the 'read' builtin to get characters from jot, but read is /also/ defined to apply shell field splitting rules. A correct version of your test follows: #!/bin/sh -x for n in `jot 256 0` do c="`jot -c 1 $n`" echo "$c" | wc -c | grep -v 2 && echo "$n" done which correctly produces the following output: 1 0 1 10 because a shell variable cannot contain a null character (which is a string end marker), and backquote expansion is defined to remove trailing newlines. This is legal and expected behaviour, not a bug. Thomas. -- Thomas.Quinot@Cuivre.FR.EU.ORG On Tue, Nov 06, 2001 at 06:18:34PM +0100, Thomas Quinot wrote:
> > #!/bin/sh
> > string=`printf "\21"`
> > echo $string | hd
>
> > Replace 21 with 201 and rerun. You see:
> > 00000000 0a |.|
> > 00000001
>
> Can't reproduce here for the value \201, but for the other values
> you mention it looks like perfectly normal and expected behaviour
> from sh(1). It is not surprising at all that some characters "disappear"
> here: since $string appears unquoted, any character which is whitespace
> w.r.t. shell parsing rules won't be passed to echo.
> Try to quote your string:
> echo "$string" | hd
I still get unexpected results:
#!/bin/sh
string=`printf "\210"`
echo "$string" | hd
gives me:
00000000 0a |.|
00000001
The same with \12 and \201. Other codes are Ok, thank you for explanation.
I see that \12 is removed by backquotes but wonder what with \201 and \210.
Eugene Grosbein
Le 2001-11-06, Eugene Grosbein écrivait : > I still get unexpected results: You are absolutely right. My tests succeeded because I tried your script on -CURRENT, where this bug was fixed a few weeks ago. The fix to -STABLE was MFC'd last week: Revision 1.31.2.3 Branch: RELENG_4 MFC: BASESYNTAX, DQSYNTAX, SQSYNTAX and ARISYNTAX handles negative indexes. Allow those to be used to properly quote characters in the shell control character range. PR: 31627 so updating your /bin/sh with the latest -STABLE version should resolve your problem. Thomas. -- Thomas.Quinot@Cuivre.FR.EU.ORG State Changed From-To: open->closed Fixed by tegge in -current and RELENG_4. On Tue, Nov 06, 2001 at 08:51:13PM +0100, Thomas Quinot wrote:
> > I still get unexpected results:
> You are absolutely right. My tests succeeded because I tried your
> script on -CURRENT, where this bug was fixed a few weeks ago.
> The fix to -STABLE was MFC'd last week:
>
> Revision 1.31.2.3
> Branch: RELENG_4
>
> MFC: BASESYNTAX, DQSYNTAX, SQSYNTAX and ARISYNTAX handles negative
> indexes.
> Allow those to be used to properly quote characters in the shell
> control character range.
>
> PR: 31627
>
> so updating your /bin/sh with the latest -STABLE version should resolve
> your problem.
I've updated to -STABLE and this works now as expected.
Thank you very much. PR should be closed now.
Eugene Grosbein
|