Top Forums UNIX for Dummies Questions & Answers Foreach loop through subdirectories in csh Post 302910709 by saleheen on Sunday 27th of July 2014 02:38:37 PM
Foreach loop through subdirectories in csh


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 C2H3O1/, C2H4O1/...let's say under C2H3O1/ I have several subdirectories like CH2CH2OH/, CH3CH2O/, CH3CHOH/. Inside each sub-directories I have several child directories likeVAS-S0001-001-Ru_001/,VAS-S0001-002-Ru_001/,VAS-S0001-003-Ru_001/. Inside all of them reside OPT-0/, OPT-1/ inside which my job input files and job scripts reside. I wrote a script that I'd like to run inside each child directory that modifies some input files and submits the job. I would like to run my script one time under C-H that'll go through each directory and submit my job.

Here's the silly thing that I have:
set dir=`*/*/*/*/`
foreach $dir

I know I'm doing something very very wrong, I don't have a counter for the foreach but how do I set that since the number of directories might be different for different cases? Thanks a lot!
Test Your Knowledge in Computers #469
Difficulty: Medium
The NTP pool is a dynamic collection of networked computers that volunteer to provide highly accurate time via the Network Time Protocol to clients worldwide.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Foreach loop

What am I doing wrong with this foreach loop? foreach var ($argv) @sum = $sum + $var (4 Replies)
Discussion started by: haze21
4 Replies

2. Shell Programming and Scripting

foreach loop

Hi Guys, I have a loop which uses a wildcard i.e. foreach f (*) but when I execute the tcsh file in unix then it gives me an error ->>>>>>>foreach: words not parenthesized<<<<<<<<<<- Any help. (1 Reply)
Discussion started by: abch624
1 Replies

3. Shell Programming and Scripting

foreach loop

Hi everyone Does anyone know what is wrong with this script. i keep getting errors foreach filename (`cat testing1`) set string=$filename set depth=`echo "$string" echo $depth end the error is the following testing: line 1: syntax error near unexpected token `(' testing: line 1:... (3 Replies)
Discussion started by: ROOZ
3 Replies

4. UNIX for Advanced & Expert Users

Problem with foreach loop

Hi All, Is there any problem with the below 'foreach' loop? foreach risk_factor ($(cat "$rf_list")) where "rf_list=$SCRIPT/Utility/rflist.txt " I'm wondering, it is throwing below error message: syntax error at line 34: `(' unexpected Any idea/suggestions ? Thanks in advance /... (7 Replies)
Discussion started by: ganapati
7 Replies

5. Shell Programming and Scripting

Using sed with a foreach loop

So I am back again beating my head against the wall with a shell script and getting a headache! I want to change each year in a file (1980, 1981, 1982, 1983, etc.) to the same year followed by a tab. The input is "blah blah (1980) blah blah". I want to get "blah blah (1980 ) blah blah".... (2 Replies)
Discussion started by: Peggy White
2 Replies

6. Shell Programming and Scripting

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. foreach f ( *$searchpt* ) set fnew = `echo $f | awk -v searchpat=$searchpt \ ... (1 Reply)
Discussion started by: kristinu
1 Replies

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

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

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

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
DH_INSTALLINIT(1)						     Debhelper							 DH_INSTALLINIT(1)

dh_installinit - install upstart jobs or init scripts into package build directories SYNOPSIS
dh_installinit [debhelperoptions] [--name=name] [-n] [-R] [-r] [-d] [-O] [--params] DESCRIPTION
dh_installinit is a debhelper program that is responsible for installing upstart job files or init scripts with associated defaults files into package build directories, and in the former case providing compatibility handling for non-upstart systems. It also automatically generates the postinst and postrm and prerm commands needed to set up the symlinks in /etc/rc*.d/ and to start and stop the init scripts. FILES
debian/package.upstart If this exists, it is installed into etc/init/package.conf in the package build directory. debian/package.init Otherwise, if this exists, it is installed into etc/init.d/package in the package build directory. debian/package.default If this exists, it is installed into etc/default/package in the package build directory. OPTIONS
-n, --noscripts Do not modify postinst/postrm/prerm scripts. -o, --onlyscripts Only modify postinst/postrm/prerm scripts, do not actually install any init script, default files, or upstart job. May be useful if the init script or upstart job is shipped and/or installed by upstream in a way that doesn't make it easy to let dh_installinit find it. If no upstart job file is installed in the target directory when dh_installinit --onlyscripts is called, this program will assume that an init script is being installed and not provide the compatibility symlinks or upstart dependencies. -R, --restart-after-upgrade Do not stop the init script until after the package upgrade has been completed. This is different than the default behavior, which stops the script in the prerm, and starts it again in the postinst. This can be useful for daemons that should not have a possibly long downtime during upgrade. But you should make sure that the daemon will not get confused by the package being upgraded while it's running before using this option. -r, --no-restart-on-upgrade Do not stop init script on upgrade. --no-start Do not start the init script on install or upgrade, or stop it on removal. Only call update-rc.d. Useful for rcS scripts. -d, --remove-d Remove trailing d from the name of the package, and use the result for the filename the upstart job file is installed as in etc/init/ , or for the filename the init script is installed as in etc/init.d and the default file is installed as in etc/default/ . This may be useful for daemons with names ending in d. (Note: this takes precedence over the --init-script parameter described below.) -uparams --update-rcd-params=params -- params Pass params to update-rc.d(8). If not specified, defaults will be passed to update-rc.d(8). --name=name Install the upstart job file or the init script (and default file) using the filename name instead of the default filename, which is the package name. When this parameter is used, dh_installinit looks for and installs files named debian/, debian/ and debian/, instead of the usual debian/package.upstart, debian/package.init and debian/package.default. --init-script=scriptname Use scriptname as the filename the init script is installed as in etc/init.d/ (and also use it as the filename for the defaults file, if it is installed). If you use this parameter, dh_installinit will look to see if a file in the debian/ directory exists that looks like package.scriptname and if so will install it as the init script in preference to the files it normally installs. This parameter is deprecated, use the --name parameter instead. This parameter will be ignored completely for upstart jobs. --upstart-only Only install an upstart job file, and do not include maintainer script code to replace an init script with that upstart job. This parameter is intended for use when the "package.upstart" file is new and only to be used on Upstart-based systems. --error-handler=function Call the named shell function if running the init script fails. The function should be provided in the prerm and postinst scripts, before the #DEBHELPER# token. NOTES
Note that this command is not idempotent. dh_prep(1) should be called between invocations of this command. Otherwise, it may cause multiple instances of the same text to be added to maintainer scripts. SEE ALSO
debhelper(7) This program is a part of debhelper. AUTHORS
Joey Hess <> Steve Langasek <> Scott James Remnant <> 8.9.0ubuntu2.1 2012-06-12 DH_INSTALLINIT(1)
All times are GMT -4. The time now is 05:02 AM.
Unix & Linux Forums Content Copyright 1993-2020. All Rights Reserved.
Privacy Policy