Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Nov 2001 18:18:34 +0100
From:      Thomas Quinot <thomas@cuivre.fr.eu.org>
To:        Eugene Grosbein <eugen@svzserv.kemerovo.su>
Cc:        stable@freebsd.org, freebsd-gnats-submit@freebsd.org
Subject:   Re: bin/31627 sh(1) is broken - loss of data!
Message-ID:  <20011106181834.A23607@melusine.cuivre.fr.eu.org>
In-Reply-To: <3BE8125B.E7DA340C@svzserv.kemerovo.su>; from eugen@svzserv.kemerovo.su on Tue, Nov 06, 2001 at 11:39:55PM %2B0700
References:  <3BE8125B.E7DA340C@svzserv.kemerovo.su>

next in thread | previous in thread | raw e-mail | index | archive | help
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

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




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