Re: Parallel programming with FORALL?



David Thompson <dave.thompson2@xxxxxxxxxxx> wrote:
(snip, I wrote)


The Unix C shell (/bin/csh) also has a similar foreach construct.
You can do things like:

foreach i ( `ls *.f` )
echo $i
gfortran $i
end

(snip)

But in both cases it is better to just use *.f instead of `ls *.f`
since the latter must be tokenized and if any of your filenames
include whitespace will produce wrong results, whereas globbing is
done in the shell and preserved (except in the very oldest original
shells no one would encounter by accident today). And if you have any
directories named something.f the former will give a clearer error
message, but neither will work right so don't do that.

When I was first working with unix, someone wrote a csh script
for me similar to:

#!/bin/csh
foreach i ( *$1* )
set j=`echo $i | sed s/$2/$3/`
echo mv $i $j
mv $i $j
end

(well, I have rewritten it a few times since, so it might not
be quite the same)

This allows one to do what on other systems can be done
with a rename command, like

rename *.for *.xyz

or

rename abc.* xyz.*

or a few other combinations that were useful at the time.

But I have also done foreach with more complicated `` expressions,
such as ones containing grep.

-- glen
.



Relevant Pages

  • Re: Loop variables in KSH - Linux / HPUX difference
    ... How about exporting "ts", e.g.: ... You should probably rename it to "TS" to follow the "all exported ... echo "$ts" ...
    (comp.unix.shell)
  • Re: How to through a semicolon separated list in a string
    ... call's or use delayed expansion Delayed expansion ... an echo status being displayed when the contents of the var is empty. ... >& simply a distinct command separator (which is what unconditional ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: yet another bash question
    ... remove occurrences of a string at the start ... duplicate or empty filenames ... echo "you will prepend all filenames in pwd,"; ... nice rename feature that I use to rename photos. ...
    (Debian-User)
  • Re: [PHP] How to count transfered kBytes in File-Download
    ... Michelle Konzack wrote: ... echo fread; ... "Some men are born to greatness, some achieve greatness, ...
    (php.general)
  • yet another bash question
    ... to rename the files, keeping the numerical part and coding something else in ... # any filenames, and replace it by another string, subject to avoiding ... echo "you will prepend all filenames in pwd,"; ...
    (Debian-User)