GNU bug report logs - #18987
the bourne shell printf-vs-\xHH portability trap

Previous Next

Package: grep;

Reported by: Jim Meyering <jim <at> meyering.net>

Date: Fri, 7 Nov 2014 17:15:03 UTC

Severity: normal

Done: Jim Meyering <jim <at> meyering.net>

Bug is archived. No further changes may be made.

Full log


Message #19 received at 18987 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Norihiro Tanaka <noritnk <at> kcn.ne.jp>
Cc: 18987 <18987 <at> debbugs.gnu.org>
Subject: Re: bug#18987: the bourne shell printf-vs-\xHH portability trap
Date: Fri, 7 Nov 2014 14:45:06 -0800
On Fri, Nov 7, 2014 at 2:30 PM, Norihiro Tanaka <noritnk <at> kcn.ne.jp> wrote:
> Jim Meyering <jim <at> meyering.net> wrote:
>
>> I ran grep's tests on a debian system this morning and was
>> surprised to see the word-multibyte test fail...
>> Until I realized it was because that system was configured
>> to use dash for /bin/sh, and this test relied on the unportable
>> printf '\xc3\xa1\n' to print an a (A-grave).  Using \xHH
>> hexadecimal constants works with bash and zsh, but that
>> is not portable, and dash's printf built-in emits the 9 bytes
>> rather than the expected three.
>>
>> This isn't the first time this has happened, so I'll be writing
>> a syntax-check rule to help avoid another repeat.
>>
>> Here's how I've fixed it:
>
> Thanks, but it seem that it is also unportable.  On Solaris 10 and AIX 7,
> below.  Need Gawk for tests?
>
> $ awk 'BEGIN { printf "\x41" }' </dev/null
> \x41

By the way, "no", we cannot rely on gawk for these tests.




This bug report was last modified 10 years and 198 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.