sh(1) command substitution and here documents

WU SHI-KUEI wu at spot.Colorado.EDU
Thu Jun 23 01:06:19 AEST 1988


In article <1254 at cadre.dsl.PITTSBURGH.EDU> jack at cadre.dsl.pittsburgh.edu.UUCP (Jack Nelson) writes:
> . . . an explanation of what he wants to do
>What I would like to do is incorporate this calculation result into a shell
>variable using the here document:
>	#!/bin/sh
>	var=`bc <<End
>	scale=2
>	3 / 4
>	End
>	`
> . . . error messages, why doen't it work etc.

You don't need or want the here document.  The following will do just fine:

	#!/bin/sh		# not needed with REAL UNIX
	var=`bc '
	scale = 2
	3 / 4
	quit'`

The 'quit' is essential since bc keeps reading the standard input after the command have been read.

Carl Brandauer
ihnp4!nbires!bdaemon!carl
303-442-1731



More information about the Comp.unix.wizards mailing list