Simple CSH script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple CSH script
# 1  
Old 09-25-2009
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: echo "SUCCSS"
breaksw
cae -1: echo "FAIL"
breaksw
endsw


I also tried:

if ( $Return_Code == 0 )
then echo "SUCCESS"
else echo "FAIL"
endif
# 2  
Old 09-25-2009
Quote:
Originally Posted by nimo
Hi everyone,
I have never wrote script in csh before,

Good. Keep it that way!

Top Ten Reasons not to use the C shell
Csh problems
Csh Programming Considered Harmful

Quote:
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.

Bash and csh syntax are very different.

You will probably be better off translating the entire script to a Bourne-type syntax, POSIX or bash.
# 3  
Old 09-25-2009
What I meant is that the script is csh and already exists. I need to corrct the few lines shown in my message. Thanks.
# 4  
Old 09-25-2009
Hi.

Follow the advice from cfajohnson whenever you can.

If I had to modify the csh script, I would use:
Code:
#!/usr/bin/env tcsh

# @(#) s1	Demonstrate csh case statement on separate line.

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" tcsh
echo

set Return_Code=0

switch ( $Return_Code )
case 0:
	echo "SUCCSS"
breaksw
# cae -1: echo "FAIL"
case -1:
	echo "FAIL"
breaksw
default:
	echo " Error in settings."
breaksw
endsw

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility version)
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0 
tcsh 6.14.00

SUCCSS

Each case selector must be alone on the line. Remember the importance of experimentation -- best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

2. UNIX for Dummies Questions & Answers

Problem with simple csh scripting

I found my answer... (2 Replies)
Discussion started by: sjung9442
2 Replies

3. UNIX for Dummies Questions & Answers

Csh script

Hey all, I've only just started using UNIX coding on my Masters project, so am still learning!! The script I've been writing is literally just for me to get used to writing it and seeing what I can do with some data I've been given. I'm trying to write a script, where the penultimate line... (2 Replies)
Discussion started by: southernlight
2 Replies

4. Shell Programming and Scripting

csh script help

Hey I am brand new to this forum and scripting. I have several documents (1000+) all formated exactly the same. Each document contains 97 lines. I want to pull 3 lines from the documents to populate a file. These 3 lines are line number 9, 24, and 58. Ok my questions: Instead of using... (3 Replies)
Discussion started by: david6789
3 Replies

5. Shell Programming and Scripting

how to source csh script in tcl script

i have atcl script and i want to source a csh script to reflect changes done by script ........ Please help....... (0 Replies)
Discussion started by: paragarora47
0 Replies

6. Shell Programming and Scripting

Help with csh script

Ok I asked something similar earlier with no response, so maybe I didn't word it correctly. I'm new at this, so thank you for your help. Here's what I have right now. ---------------------------- > cat MySourceFile #!/bin/csh echo "Please Enter Value For My_Env_Var:" set answer = $< ... (1 Reply)
Discussion started by: MMorrison
1 Replies

7. 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

8. Shell Programming and Scripting

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. ... (2 Replies)
Discussion started by: two reelers
2 Replies

9. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

10. UNIX for Dummies Questions & Answers

a simple loop in csh

Hello, I have a file with over 48000 lines and I need to select certain parts of the file. I know which awk commands work for what I need, I just need some help putting together a loop that will repeat the command. These are the commands that work: awk 'NR < 6' plot.out > plot.test (I get... (1 Reply)
Discussion started by: dsstamps
1 Replies
Login or Register to Ask a Question