[comp.unix.ultrix] Bug in /bin/sh??

jbrayton@mipos2.intel.com (Jim Brayton) (07/01/89)

The following appears to be a bug in /bin/sh under Ultrix 2.2 and 3.1 (the only
Ultrix system's I have access to):

The short shell program:

=================================
#!/bin/sh

bogus=`cat << END
a
END
`

/bin/echo $bogus
=================================

should print an 'a' when run, instead under Ultrix it reports an error message like:

	/tmp/sh108410: cannot open

I've tried this under SunOS 4.0 and it works as expected.  Is this a known problem with
Ultrix?

	- jim brayton -


===============================================================================
Jim Brayton, Microprocessor Design, Intel Corp.
UUCP: {decwrl,hplabs,oliveb}!intelca!mipos3!mipos2!jbrayton
ARPA: jbrayton%mipos2.intel.com@relay.cs.net

maart@cs.vu.nl (Maarten Litmaath) (07/04/89)

jbrayton@mipos2.intel.com (Jim Brayton) writes:
\...
\#!/bin/sh
\
\bogus=`cat << END
\a
\END
\`
\
\/bin/echo $bogus

[doesn't work as expected]

Seems a bug to me indeed. On the other hand though I'd expect the following
to work TOO:

	#!/bin/sh

	foo=`cat` << EOF
	bar
	EOF

	echo $foo

Did you try this?
-- 
"I HATE arbitrary limits, especially when |Maarten Litmaath @ VU Amsterdam:
   they're small."  (Stephen Savitzky)    |maart@cs.vu.nl, mcvax!botter!maart

david@ms.uky.edu (David Herron -- One of the vertebrae) (07/04/89)

Something like

	(
	cat >a <<'EOF'
	stuff
	EOF
	)

will also fail in the same way, saying that it can't create some file
in /tmp.

I used to use that sort of thing heavily in my scripts, until we
switched to Ultrix...

I think it was always failing in contexts where the "here-document"
was in a sub-process.
-- 
<- David Herron; an MMDF guy                              <david@ms.uky.edu>
<- ska: David le casse\*'      {rutgers,uunet}!ukma!david, david@UKMA.BITNET
<-
<- New word for the day: Obnoxity -- an act of obnoxiousness

ccea3@rivm.UUCP (Adri Verhoef) (07/05/89)

From sh(1) of TFM of version 3.0:

RESTRICTIONS
   If  <<  is used to provide standard input to an asynchronous process
   invoked by  & , the shell gets mixed up about naming the input document.
   A garbage file  /tmp/sh*  is created, and the shell complains about not
   being able to find the file by another name.

guy@auspex.auspex.com (Guy Harris) (07/06/89)

 >...instead under Ultrix it reports an error message like:
 >
 >	/tmp/sh108410: cannot open
 >
 >I've tried this under SunOS 4.0 and it works as expected.  Is this a known
 >problem with Ultrix?

It sounds similar to another known problem with older versions of the
Bourne shell, in which the shell gets confused about the name of the
"here document" file (the thing between "<<" and the end-of-file
marker).  The known problem in question was fixed in some later version
of the Bourne shell (the S5R2 version, I think), and this problem may
have been fixed there as well.

SunOS has used an S5R2-or-later version of the Bourne shell as "/bin/sh"
since SunOS 3.0; presumably, Ultrix is still using the V7-vintage BSD
version as its "/bin/sh".  If you have a System V shell as "/bin/5sh" or
somesuch, you might try using that to run your script (using the "#!"
mechanism) instead (although putting something like "/bin/5sh" or
somesuch into the "#!" line means your script won't work on systems that
don't have a program with that pathname, so your script may work only on
Ultrix if that line is there).

mellon@zayante.pa.dec.com (Ted Lemon) (07/06/89)

Ultrix does come with a /bin/sh5, which is supposedly a System V
Bourne shell.   I've no idea why it isn't the default.

			       _MelloN_

david@ms.uky.edu (David Herron -- One of the vertebrae) (07/06/89)

In article <1394@rivm05.UUCP> a3@rivm.UUCP (Adri Verhoef) writes:
>From sh(1) of TFM of version 3.0:
>
>RESTRICTIONS

[The same bug listing that's been on the sh(1) manual page from at least v7]

In my case I have lots of scripts which are run out of cron at various
times of the day.  I tend to put (..)'s around the whole script so that
I can redirect the output of the entire script to a log file.  I also
tend, when I need a "procedure", to cat the procedure out to a script
file in a "here" document and then execute that.  This all worked fine
and perfectly under Ultrix v2.2, SunOS v3.4, and Dynix v2.? and v3.?.

It started breaking when we upgraded to Ultrix v3.0 but continued to
work on the other machines.  Even with upgrading the Sun's to v4.1.

Mark Evans tells me by mail:


From: evans@decvax.zk3.dec.com
To: jbrayton@mipos2.intel.com, maart@star.cs.vu.nl, 
    ukma!david@decvax.zk3.dec.com
Subject: RE: Bug in /bin/sh??
Date: Wed, 05 Jul 89 16:49:08 EDT

(I would post this to the net, but alas, my xrn program seems to be broken and
I can not. You are welcome to forward this to the net...)

If you use /bin/sh5, this will solve your immediate problem. This unfortunately
is not very portable, but is the mechanism that DEC decided to provide for
SYS V compatability.

- Marc Evans
-- 
<- David Herron; an MMDF guy                              <david@ms.uky.edu>
<- ska: David le casse\*'      {rutgers,uunet}!ukma!david, david@UKMA.BITNET
<-
<- New word for the day: Obnoxity -- an act of obnoxiousness

douglas@dekalb.UUCP (Douglas B. Jones) (07/12/89)

In article <400@mipos3.intel.com> jbrayton@mipos2.intel.com (Jim Brayton) writes:
=The following appears to be a bug in /bin/sh under Ultrix 2.2 and 3.1 (the only
=Ultrix system's I have access to):
=The short shell program:
==================================
=#!/bin/sh
=bogus=`cat << END
=a
=END
=`
=/bin/echo $bogus
==================================
=should print an 'a' when run, instead under Ultrix it reports an error message like:
=	/tmp/sh108410: cannot open
=I've tried this under SunOS 4.0 and it works as expected.  Is this a known problem with
=Ultrix?
=	- jim brayton -
=Jim Brayton, Microprocessor Design, Intel Corp.
=UUCP: {decwrl,hplabs,oliveb}!intelca!mipos3!mipos2!jbrayton
=ARPA: jbrayton%mipos2.intel.com@relay.cs.net

One note about the above, you are useing the '/bin/sh' instead of '/bin/sh5'.
The SunOS 4.0 might be useing the 'sh' that conforms to the SYSTEM V. Where
the above above 'sh5' conforms to SYSTEM V Release 2 (according to the man
page here under ULTRIX 3.0). I have not look through the man page for
'/bin/sh', but I don't think it says that it is a 100% compatible to ATT sh.

I think the '/bin/sh' comes from BSD.

Hope this helps some.







These lines added 

to take care


of the Pnews message about 
more old text than new text




-- 
Doulas B. Jones					douglas@dekalb
Academic Computer Center		or	gatech!dekalb!douglas
DeKalb College
555 N. Indian Creek Drive/Clarkston, Ga. 30021