Sponsored Content
Full Discussion: foreach in csh
Top Forums Shell Programming and Scripting foreach in csh Post 302493588 by kristinu on Thursday 3rd of February 2011 07:08:23 AM
Old 02-03-2011
foreach in csh

I have a foreach loop in a csh script and I noticed that it tries to find the files with the pattern *$searchpt* in the file name. I'm confused as I never specified checking for the files.

Code:
    foreach f ( *$searchpt* )
      set fnew = `echo $f | awk -v searchpat=$searchpt    \
                                -v replacepat=$replacept  \
                                '{sub(searchpat,replacepat); print}'`
      endif

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

foreach/grep help!

#!/bin/bash foreach x (67402996 67402998) { grep -a x FINAL2006.dat >> MISSING_RECORDS.dat } I'm trying to pass a list to the variable x, and then grep for that string in FINAL2006.dat... Final2006.dat is in the same folder as my .sh file. I call this with a .cmd file... At any rate,... (6 Replies)
Discussion started by: JimWork
6 Replies

2. Shell Programming and Scripting

foreach folder

Hi, I'm having a small issue here and I can't get it to work. I'm programming a script for bash and I need to do something to all the folder in a directory. So I'm in the directory and I want to use the foreach statement but I dont know how to reference all the folders of that directory. To make... (7 Replies)
Discussion started by: eltinator
7 Replies

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

4. Shell Programming and Scripting

How to count using foreach

I have a simple csh script that has a simple foreach loop that goes over numbers, from 1 to 10: foreach n(1 2 3 4 5 6 7 8 9 10) ... end Now I want to expand the script to work on over a hundred consecutive n values. Obviously, typing all the numbers between 1 to 100 is an unreasonable... (7 Replies)
Discussion started by: mcbenus
7 Replies

5. Shell Programming and Scripting

Learning foreach

im newbie at shell scripting. why do the following code #!/bin/tcsh setenv CBC ~/cbc/models/ foreach mix (p00p00 p02p00 p02p04) echo $mix cp $CBC/*$mix*Gyr*fits $mix/ end print(copy) only the first mix? % ./copyfromcbc.sh p00p00 wasn't it supposed to run through all words... (0 Replies)
Discussion started by: prtc
0 Replies

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

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

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

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

10. Shell Programming and Scripting

Foreach: Words not parenthesized. csh

Just started shell scripting for the first time today :D Can anyone tell me why I get the error "foreach: Words not parenthesized." for my following code? The program takes in a list of arguments. foreach card ($argv) echo Hello end (3 Replies)
Discussion started by: pkuebler
3 Replies
foreach(3tcl)						       Tcl Built-In Commands						     foreach(3tcl)

__________________________________________________________________________________________________________________________________________________

NAME
foreach - Iterate over all elements in one or more lists SYNOPSIS
foreach varname list body foreach varlist1 list1 ?varlist2 list2 ...? body _________________________________________________________________ DESCRIPTION
The foreach command implements a loop where the loop variable(s) take on values from one or more lists. In the simplest case there is one loop variable, varname, and one list, list, that is a list of values to assign to varname. The body argument is a Tcl script. For each element of list (in order from first to last), foreach assigns the contents of the element to varname as if the lindex command had been used to extract the element, then calls the Tcl interpreter to execute body. In the general case there can be more than one value list (e.g., list1 and list2), and each value list can be associated with a list of loop variables (e.g., varlist1 and varlist2). During each iteration of the loop the variables of each varlist are assigned consecutive values from the corresponding list. Values in each list are used in order from first to last, and each value is used exactly once. The total number of loop iterations is large enough to use up all the values from all the value lists. If a value list does not contain enough elements for each of its loop variables in each iteration, empty values are used for the missing elements. The break and continue statements may be invoked inside body, with the same effect as in the for command. Foreach returns an empty string. EXAMPLES
This loop prints every value in a list together with the square and cube of the value: set values {1 3 5 7 2 4 6 8} ;# Odd numbers first, for fun! puts "Value Square Cube" ;# Neat-looking header foreach x $values { ;# Now loop and print... puts " $x [expr {$x**2}] [expr {$x**3}]" } The following loop uses i and j as loop variables to iterate over pairs of elements of a single list. set x {} foreach {i j} {a b c d e f} { lappend x $j $i } # The value of x is "b a d c f e" # There are 3 iterations of the loop. The next loop uses i and j to iterate over two lists in parallel. set x {} foreach i {a b c} j {d e f g} { lappend x $i $j } # The value of x is "a d b e c f {} g" # There are 4 iterations of the loop. The two forms are combined in the following example. set x {} foreach i {a b c} {j k} {d e f g} { lappend x $i $j $k } # The value of x is "a d e b f g c {} {}" # There are 3 iterations of the loop. SEE ALSO
for(3tcl), while(3tcl), break(3tcl), continue(3tcl) KEYWORDS
foreach, iteration, list, looping Tcl foreach(3tcl)
All times are GMT -4. The time now is 07:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy