simple CSH Script behaves differently on Solaris and RedHat Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting simple CSH Script behaves differently on Solaris and RedHat Linux
# 1  
Old 02-02-2009
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.
# 2  
Old 02-02-2009
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:
Code:
#!/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:
Code:
$ ./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.
# 3  
Old 02-02-2009
Thanks!

It works that way!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

'Connect' behaves differently on Solaris 11

Our application fails to run successfully on Solaris 11. The same works fine in Solaris 10. Due to which we are unable to migrate to Solaris 11. The app basically involves forking a child process, which finally connects with parent process. But on Solaris 11, it is unable to connect with parent... (0 Replies)
Discussion started by: wini008
0 Replies

2. Shell Programming and Scripting

su - user -c 'command' behaves differently

I notice that su - user (note with dash) brings in more of the user's environment than does su - user -c 'command'. For example, if root does an su - user, and types "umask" to the prompt, one umask is displayed; yet, if instead the command is su - user -c 'umask', the value is different. I thought... (2 Replies)
Discussion started by: drokerm
2 Replies

3. Shell Programming and Scripting

Executing a script from CRON behaves differently than terminal

Hi have a script which transferers from Microsoft server to Linux box. The scripts(ksh) is on Linux box. If I run script from terminal, it transfers files to directory. Where as If I run script from CRON. It does not. Here is the log of both: Terminal execution log:... (2 Replies)
Discussion started by: dipeshvshah
2 Replies

4. Shell Programming and Scripting

simple csh script

Hi This little script is giving me error: Syntax error at line xxx : `(' is not expected. Wgat did I miss? RC=0 switch ( $RC ) case 0: echo Done breaksw case -1: echo not done breaksw default: echo "Hello" endsw (2 Replies)
Discussion started by: nimo
2 Replies

5. Shell Programming and Scripting

Simple CSH script

Hi everyone, I have never wrote script in csh before, but I need to add only few lines to an existing one. I tried to use the bash standard syntax, and it did not work. So, I attempted to use csh syntax, and it is not working. Can someone help please: switch ( $Return_Code ) case 0:... (3 Replies)
Discussion started by: nimo
3 Replies

6. Windows & DOS: Issues & Discussions

Awk script in DOS and Linux behaves differently :(

Hi, I have an awk script which performs simple operations of variable assignments and finally printing the variables in custom form. BEGIN {FS=OFS="\n"} { v1=substr($0,1,15) v2=substr($0,16,200) v3=substr($0,216,20) print v1 "|" v2 "|" v3 } The input file being processed... (2 Replies)
Discussion started by: vidyak
2 Replies

7. UNIX for Dummies Questions & Answers

need solaris /etc/default/fs equivalent file in redhat Linux

contents of /etc/default/fs file in solaris are @:/root !ksh less /etc/default/fs LOCAL=ufs i want to retrieve same LOCAL variable in redhat Linux... any1 knows path of corresponding file in Linux? (0 Replies)
Discussion started by: crackthehit007
0 Replies

8. UNIX for Advanced & Expert Users

Solaris or RedHat Linux

Dear All Experts, Would like to know the maturity/ stability of Redhat Linux AS 3.0 versus Solaris. My organization need to setup cluster solution. We are well-versed with Veritas Cluster on Solaris. We are thinking of waiting for certification support of the various ISV like Oracle,... (1 Reply)
Discussion started by: izy100
1 Replies

9. UNIX for Advanced & Expert Users

Application can't startup?? Solaris and Linux RedHat

can someone tell me what could cause an application not to startup? I'm getting calls from users saying they cant' startup a particular application. how do I troubleshoot this? i tried doing ps -ef | grep (application) i saw the application running. now, am wondering, would it be safe to... (1 Reply)
Discussion started by: TRUEST
1 Replies

10. UNIX for Dummies Questions & Answers

linux redhat and solaris NIS+

Hello all, I am wondering if anyone had success with installing a redhat linux (PC box) on a Solaris NIS+ network. I have gotten information on how to do this but have been unsuccessful. The information that I have gotten is a little out dated and is not 100%. ... (0 Replies)
Discussion started by: larry
0 Replies
Login or Register to Ask a Question