sh(1) command substitution and here documents
Mike "Ford" Ditto
ford at elgar.UUCP
Fri Jun 24 16:46:55 AEST 1988
In article <1254 at cadre.dsl.PITTSBURGH.EDU> jack at 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 <<End
> 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 at kenobi.cts.com
This was a Pizza Hut, ...!sdcsvax!crash!kenobi!ford
now it's all covered with daisies." -- Talking Heads
More information about the Comp.unix.wizards
mailing list