Path: utzoo!attcan!uunet!seismo!esosun!ucsdhub!jack!elgar!ford
From: ford@elgar.UUCP (Mike "Ford" Ditto)
Newsgroups: comp.unix.wizards
Subject: Re: sh(1) command substitution and here documents
Message-ID: <200@elgar.UUCP>
Date: 24 Jun 88 06:46:55 GMT
References: <1254@cadre.dsl.PITTSBURGH.EDU>
Reply-To: ford@kenobi.cts.com (Mike "Ford" Ditto)
Organization: Omnicron Data Systems,  Bonita, CA
Lines: 34

In article <1254@cadre.dsl.PITTSBURGH.EDU> jack@cadre.dsl.pittsburgh.edu.UUCP (Jack Nelson) writes:
>What I would like to do is incorporate this calculation result into a shell
>variable using the here document:
>	#!/bin/sh
>	var=`bc <	scale=2
>	3 / 4
>	End
>	`
>But this doesn't work; an error message "cannot open /tmp/sh01383"
>always is produced, both on 4.3 and 2.10 systems.

Both command-substitution and here-files use a temporary file, and
apparrently they use the same name.  I'd call it a bug.

But I'd do it like this anyway:

	#!/bin/sh
	var=`echo 'scale=2
	3 / 4' | bc`

Or better yet,

	var=`echo 2k 3 4 /p | dc`

which is more efficient and also works in csh (if you put a 'set' at
the beginning).

					-=] Ford [=-

"Once there were parking lots,		(In Real Life:  Mike Ditto)
now it's a peaceful oasis.		ford@kenobi.cts.com
This was a Pizza Hut,			...!sdcsvax!crash!kenobi!ford
now it's all covered with daisies." -- Talking Heads