IF is not working in csh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting IF is not working in csh script
# 1  
Old 10-16-2012
IF is not working in csh script

cat tmp0.txt
700000
Code:
#!/bin/csh -fx
set id=`cat tmp0.txt`
echo $id
if ("$id" == "700000") then
   echo "Good Morning"
endif
if ("$id" == "700002") then
         echo "Good evening"
 endif

My output from terminal
Code:
set id=`cat tmp0.txt`
cat tmp0.txt
echo 700000 
700000 
 == 700000 ) then
 == 700002 ) then

Moderator's Comments:
Mod Comment code tags please


Seems like the IF is not working. Is there anything wrong with my variable?

Last edited by jim mcnamara; 10-16-2012 at 12:39 AM..
# 2  
Old 10-16-2012
The parentheses need spaces
Code:
if ( "$id" == "700000" ) then
   echo "Good Morning"
endif
if ( "$id" == "700002" )  then
         echo "Good evening"
 endif

each ( needs a space before and after, so does each ) character.
# 3  
Old 10-16-2012
Hi jim, the code still won't work.
# 4  
Old 10-16-2012
Try:

Code:
#!/bin/csh -fx
set id=`dos2unix tmp0.txt|head -1`
echo $id
if ("$id" == "700000") then
   echo "Good Morning"
endif
if ("$id" == "700002") then
         echo "Good evening"
endif


Last edited by rdrtx1; 10-16-2012 at 10:53 AM..
This User Gave Thanks to rdrtx1 For This Post:
# 5  
Old 10-16-2012
Following up on rdrtx1's post:
when you do this:
Code:
vi tmp0.txt

Do you see ^M at the end of each line?
# 6  
Old 10-17-2012
I opened tmp0.txt with different kind of editor, i.e vi and nedit, even with notepad and I don't see ^M . Just a number 700000

---------- Post updated at 11:41 AM ---------- Previous update was at 11:40 AM ----------

Same result, it doens't do what it suppose to do.
# 7  
Old 10-17-2012
can you post the output of the below command

Code:
 
od -c tmp0.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

>& redirection not working within csh script

I'm having a strange problem with basic >& output redirection to a simple log file in csh. When I run this particular output redirection on the command line, it works, but then when I run the same output redirection command >& in my c shell script, I get a blank log file. Nothing is output to the... (5 Replies)
Discussion started by: silencio
5 Replies

2. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

3. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

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

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

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

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

8. UNIX for Dummies Questions & Answers

Perl search and replace not working in csh script

I am using perl to perform a search and replace. It works at the command line, but not in the csh shell script perl -pi -e 's@/Pattern@@g' $path/$file I used the @ as my delimiter because the pattern contains "/" (3 Replies)
Discussion started by: NobluesFDT
3 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. Shell Programming and Scripting

#/usr/bin/csh -f not working as expected?

Hey everyone, A coworker of mine has written a csh script that starts with #!/usr/bin/csh -f. It's my understanding that the -f should skip the .cshrc and .login files, but here's the problem: In the script "line" is used, and I happen to have a "line" in my ~/bin. When the script is ran my... (4 Replies)
Discussion started by: effigy
4 Replies
Login or Register to Ask a Question