Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Nov 2001 09:20:01 -0800 (PST)
From:      Thomas Quinot <thomas@cuivre.fr.eu.org>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/31627 sh(1) is broken - loss of data!
Message-ID:  <200111061720.fA6HK1O58624@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/31627; it has been noted by GNATS.

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!
Date: Tue, 6 Nov 2001 18:18:34 +0100

 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-bugs" in the body of the message




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