simple CSH Script behaves differently on Solaris and RedHat Linux

I have a simple csh-script on a Solaris Workstaion which invokes the bc calculator:

#!/bin/csh
set shz=2
set zshift=5
set shzp=`bc -l <<END \
scale = 3 \
-1. * $shz + $zshift \
END`
echo $shzp

The result ($shzp) in this case is 3 (-1*2+5). It works fine on Solaris 8.

I have to use it on Redhat Linux (WS version 4), and there same script reports "bc: --1 Illegal option". I tried a lot of changes, and I could never derive a result. It is possibly to get the result 3 on a screen with

bc -l <<END
scale = 3
-1. * $shz + $zshift
END

but I need the result stored in $shzp.

I finally ran it under bash, and there it works after some changes. But I'm looking for a csh solution since it is only part of a large csh script, and I'm not experienced in shell programming. If anybody could help, it would be very appreciated. Thanks.

Hi.

On the CentOS version I use (CentOS: the free version of RHEL), csh is really tcsh, so there are some differences. Here is an alternate version of your script:

#!/usr/bin/env csh

# @(#) s2       Demonstrate calculation with bc in csh script.

echo
setenv LC_ALL C ; setenv LANG C
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility version)"
sh -c "version >/dev/null 2>&1" && version "=o" csh bc
echo

set shz=2
set zshift=5
set shzp=`echo "scale = 3 ; -1. * $shz + $zshift" | bc -l`

echo $shzp

exit 0

Producing:

$ ./s2

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.18-92.1.22.el5, i686
Distribution        : CentOS release 5.2 (Final)
tcsh 6.14.00 (Astron) 2005-03-25 (i386-intel-linux) options wide,nls,dl,al,kan,rh,color,filec
bc 1.06

3

It also worked on Solaris 10, and another Linux ... cheers, drl

PS Best practice: use csh only if you must, otherwise use Bourne shell family for scripting, such as sh, ksh, bash.

It works that way!