Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Jan 2000 10:25:07 -0800 (PST)
From:      "Eric J. Schwertfeger" <ejs@bfd.com>
To:        Oliver Fromme <olli@dorifer.heim3.tu-clausthal.de>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Poss bug in /bin/sh?
Message-ID:  <Pine.BSF.4.10.10001051000370.13980-100000@harlie.bfd.com>
In-Reply-To: <200001051738.SAA36801@dorifer.heim3.tu-clausthal.de>

next in thread | previous in thread | raw e-mail | index | archive | help

On Wed, 5 Jan 2000, Oliver Fromme wrote:

> Eric J. Schwertfeger <ejs@bfd.com> wrote in list.freebsd-questions:
>  > cat >> confdefs.h <<EOF
>  > #define PTY_BSD_SCHEME_FIRST_CHARS "`ls /dev/pty* | cut -c 9-9 | uniq | tr -d '\n'`"
>  > EOF
>  > [...]
>  > running the same under bash produces the desired output. What's wrong
>  > here?  Yes, this is part of the configure script, if it looks strange,
>  > though with my limited shell knowledge, I'd still expect it to work.
> 
> >From the sh(1) manpage:
> 
>    If the delimiter as specified on the initial line is quoted,
>    then the here-doc-text is treated literally, otherwise the
>    text is subjected to parameter expansion, command
>    substitution, and arithmetic expansion (as described in the
>    section on `Expansions'').

I understand this, and should have been more specific.  I'd expect shell
expansion in this case, and it obviously is expanding, given the output
below. What I don't expect is output of 

#define PTY_BSD_SCHEME_FIRST_CHARS ""
#define PTY_BSD_SCHEME_SECOND_CHARS ""

So my question wasn't expanding vs not expanding, it was why isn't it
expanding the way I'd expect it to, and why the error from sort.  The
output of the lines, when done on a seperate line is as expected.  In
fact, I can't reproduce this behavior anywhere except within
here-doc-text.

The following does work correctly, and I don't understand why there should
be a difference, as it's doing the same substitution, but storing into an
intermediate variable. 

first=`ls /dev/pty* | cut -c 9-9 | uniq | tr -d '\n'`
cat >> confdefs.h <<EOF
#define PTY_BSD_SCHEME_FIRST_CHARS "$first"
EOF

> So /bin/sh works perfectly correct.  Bash probably doesn't.

Right.  I didn't go into this assuming bash was correct and sh wasn't,
only that bash was giving me the expected behavior and sh wasn't.  The
error could as easily (more easily, actually) be that the expected
behavior is incorrect.



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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10001051000370.13980-100000>