Creating a loop in csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a loop in csh
# 1  
Old 09-18-2010
Creating a loop in csh

I have the following code and want to use a loop to output the results to the fparams file.

Code:
if ($optparams == 1) then

# Set the tdarwin parameters

    set txt01 = "Call to raytrac.csh"
    set txt02 = ""
    set txt03 = "./Scripts/raytrac.csh $*"
    set txt04 = ""
    set txt05 = "Call to Tommy raytrac program"
    set txt06 = ""
    set txt07 = "$tpath/raytrac vmod=$vmod srfile=$srfile rcfile=$rcfile    \
        phases=$phases level=$level format=$format dtau=$dtau mdacc=$mdacc  \
        mindist=$mindist maxitertp=$maxitertp out=$out ray=$ray  \
        vrb=$vrb |& tee $frtlog"
    set txt08 = ""
    set txt09 = "Parameters used in Tommy raytrac run"
    set txt10 = ""
    set txt11 = "$tpath/raytrac          \ "
    set txt12 = "  vmod=$vmod            \ "
    set txt13 = "  srfile=$srfile        \ "
    set txt14 = "  rcfile=$rcfile        \ "
    set txt15 = "  phases=$phases        \ "
    set txt16 = "  level=$level          \ "
    set txt17 = "  format=$format        \ "
    set txt18 = "  dtau=$dtau            \ "
    set txt19 = "  mdacc=$mdacc          \ "
    set txt20 = "  mindist=$mindist      \ "
    set txt21 = "  maxitertp=$maxitertp  \ "
    set txt22 = "  out=$out              \ "
    set txt23 = "  ray=$ray              \ "
    set txt24 = "  vrb=$vrb |& tee $frtlog"

# Save the tdarwin run to the .params file

    echo $txt01 > $fparams
    echo "  "$txt02 >> $fparams
    echo "  "$txt03 >> $fparams
    echo "  "$txt04 >> $fparams
    echo "  "$txt05 >> $fparams
    echo "  "$txt06 >> $fparams
    echo "  "$txt07 >> $fparams
    echo "  "$txt08 >> $fparams
    echo "  "$txt09 >> $fparams
    echo "  "$txt10 >> $fparams
    echo "  "$txt11 >> $fparams
    echo "  "$txt12 >> $fparams
    echo "  "$txt13 >> $fparams
    echo "  "$txt14 >> $fparams
    echo "  "$txt15 >> $fparams
    echo "  "$txt16 >> $fparams
    echo "  "$txt17 >> $fparams
    echo "  "$txt18 >> $fparams
    echo "  "$txt19 >> $fparams
    echo "  "$txt20 >> $fparams
    echo "  "$txt21 >> $fparams
    echo "  "$txt22 >> $fparams
    echo "  "$txt23 >> $fparams
    echo "  "$txt24 >> $fparams

endif

I'm trying to do something like this

Code:
    set text = " $txt02 $txt03 $txt04 $txt05 $txt06 $txt07 $txt08 $txt09 "
    set text = "$text $txt10 $txt11 $txt12 $txt13 $txt14 $txt15 $txt16 "
    set text = "$text $txt17 $txt18 $txt19 $txt20 $txt21 $txt22 $txt23 "
    set text = "$text $txt24"

    echo "$txt01" > $fparams
    foreach i ($text)
        echo "$i"
        echo "  "$text >> $fparams
    end



---------- Post updated at 02:50 PM ---------- Previous update was at 01:31 PM ----------

using the below gives an error somehow: Unmatched ".

Code:
    set text1 = " $txt02 $txt03 $txt04 $txt05 $txt06 $txt07 $txt08 $txt09 "


Last edited by kristinu; 09-18-2010 at 04:39 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Foreach loop through subdirectories in csh

Hi You might find it very trivial but actually don't know how to loop through all sub-directories and their child directories into a csh. bash was easier I believe but here I am, stuck with csh. So elaborately here's my problem: Let's say I have my parent directory named C-H/ under which I have... (15 Replies)
Discussion started by: saleheen
15 Replies

2. Shell Programming and Scripting

CSH While Loop

Hi all, How can I make this work with CSH: set K=3 set I=1 while ($I != $K) echo "K="$I @ I = $K + 1 end Any help you can provide or links that can help is greatly appreciated. With above I get an error "while: Expression Syntax" (3 Replies)
Discussion started by: manglalayag
3 Replies

3. UNIX for Dummies Questions & Answers

foreach loop in csh

Hi everyone I'm new to unix and encountered a small problem i couldnt find out a reason why it doesn't work..please help.. in my csh script when i tried to use the foreach loop like this: foreach x ( ls ) echo $x end when i tried to run it, it printed out 'ls' to the std out instead of... (3 Replies)
Discussion started by: ymc1g11
3 Replies

4. UNIX for Dummies Questions & Answers

Foreach loop that skips the header line of a file (csh)

Hello all, I'm working on a foreach loop to compare a couple sets of data. However, each datafile includes a header row. I'm wondering if it is possible to tell the foreach loop to skip the first line of data. I've been using the basic code as follows: foreach line ("`file.csv`") set... (2 Replies)
Discussion started by: meteorologistks
2 Replies

5. Shell Programming and Scripting

How to loop(Iterate) through List with foreach(csh)

Hey all,, I know cshell is harmful:) but I am using this just "to know" - for educational purposes!... not for a long-term use. lets say i have a list.. set arr=(x y z e f) I wanna iterate the list with foreach ,, not with while.!! foreach i $arr echo $i end does not work (2 Replies)
Discussion started by: eawedat
2 Replies

6. Shell Programming and Scripting

How to loop use while loop in csh script?

Hi all, i got 2 text file. file.txt value.txt i want use C shell script to write out while both of the file got different limit....how i going to write it in 1 while loop? (4 Replies)
Discussion started by: proghack
4 Replies

7. Shell Programming and Scripting

csh if loop variable condition check peroblem

Hi, I have variables like var1 var2 var3 var4 in if loop i am trying to check the condition if(variable == "var") then echo $variable endif (0 Replies)
Discussion started by: vasanth.vadalur
0 Replies

8. UNIX for Dummies Questions & Answers

For loop control with two variables in csh shell

Hi All How can i control for loop with two different variables in csh shell Regards Nikhil (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

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

10. Shell Programming and Scripting

csh exit while loop on keystroke

#!/bin/csh I'm using a `while(1)` loop to dispaly real-time information about various files on my system, and I use ^C to exit it when needed. I was hoping there was a way to exit the script on a normal keystroke such as "q". Can someone point me in the right direction? I'm willing to use a... (7 Replies)
Discussion started by: seg
7 Replies
Login or Register to Ask a Question