It is currently Thu, 28 Aug 2014 18:10:09 GMT



 
Author Message
 Help - specific foreach (non-csh) script?
Here's a sample of the requested syntax...

$ foreach i ( *.lha ) "lha v $i >> tempx"

What it *should* do (in this case) is to find all files in the current dir
which have an .lha suffix.  It should then lha (uncompress) in view mode
those files, and concatinate the results into the output file.

So, the first var is just a var.  The second (parenthesized) var is really
an lsf with pattern matching. The third "quoted field" var is the actual
command implemented on each matching file.

The csh version of this command could *almost* work, save for the
delimiters around the passed variables.  Heck, except for those delimiters
I could write this myself!  <wry grin>

FYI - This is the command syntax I'm using on my Amiga, and I'd REALLY like
to have a "form and function" match on my HPUX box.  Can we get there from
here?

Thanks for any help.  Awk, ksh, csh, or 'sh' solutions welcomed.  I know
I shouldn't be picky, but if you want to answer in Perl...please DON'T
bother - I don't have it on my system.

-jim-



 Fri, 28 Nov 1997 03:00:00 GMT   
 Help - specific foreach (non-csh) script?

for i in *.lha; do; lha v $i >> tempx; done

-zefram



 Fri, 28 Nov 1997 03:00:00 GMT   
 Help - specific foreach (non-csh) script?
: >$ foreach i ( *.lha ) "lha v $i >> tempx"

: for i in *.lha; do; lha v $i >> tempx; done

Heck, I knew THAT!  <friendly grin>  Thanks anyway.

Hummm....I probably asked this question the wrong way.  So, I'll try it
again.  How can I get my *script* (foreach) to do pattern substitutions
on the delimiting parens and quotes in order to match the standard 'for'
structure?  I guess what I'm really interested in is handling meta
characters in a passed parameter mode.

For example:

 the opening paren is replaced by 'in '
 the closing paren is replaced by ';'
 the opening quote is replaced by 'do;'
 the closing quote is replaced by ';done'

If we can't get there from here then I'll survive, but you'd think that
there ought to be a way.

- Save a keystroke today! -
-jim-



 Sat, 29 Nov 1997 03:00:00 GMT   
 Help - specific foreach (non-csh) script?
In comp.unix.shell,
    ai...@lvld.hp.com (Jim Aites) writes:
:Here's a sample of the requested syntax...
:
:$ foreach i ( *.lha ) "lha v $i >> tempx"
:
:What it *should* do (in this case) is to find all files in the current dir
:which have an .lha suffix.  It should then lha (uncompress) in view mode
:those files, and concatinate the results into the output file.
:
:So, the first var is just a var.  The second (parenthesized) var is really
:an lsf with pattern matching. The third "quoted field" var is the actual
:command implemented on each matching file.
:
:The csh version of this command could *almost* work, save for the
:delimiters around the passed variables.  Heck, except for those delimiters
:I could write this myself!  <wry grin>
:
:FYI - This is the command syntax I'm using on my Amiga, and I'd REALLY like
:to have a "form and function" match on my HPUX box.  Can we get there from
:here?
:
:Thanks for any help.  Awk, ksh, csh, or 'sh' solutions welcomed.  I know
:I shouldn't be picky, but if you want to answer in Perl...please DON'T
:bother - I don't have it on my system.

You'd rather have csh on your system than perl?? Go figger.

Anyway, the only "correct" version is going to have to quote stuff,
like

    for $file in *.lha; do
        lha v "$i" >> tempx
    done

Shells suck, eh? :-)

--tom
--
Tom Christiansen      Perl Consultant, Gamer, Hiker      tchr...@mox.perl.com

            "AT&T -- anything better is illegal."
                  -- Keith Lofstrom, comp.unix.bsd, "AT&T sues BSDI" thread



 Sun, 30 Nov 1997 03:00:00 GMT   
 Help - specific foreach (non-csh) script?

Well ... there are a couple of slight errors: (1) the '$file' after
the 'for' shouldn't have a leading dollar sign; (2) '$file' should
appear in the second line, not '$i' (or conversely, 'i' should appear
on the first line instead of 'file').  The code fragment should look
like this:

   for file in *.lha; do
      lha v "$file" >> tempx
   done

The above code will work in the Bourne Shell, and in bash, zsh, and
ksh. If you really want to do it in csh, then you can write it like
this:

   foreach file ( *.lha )
      lha v "$file" >> tempx
   end

Awk is not a particularly good language for this sort of thing.

The Perl solution is left as an exercise for the reader. :)

--
 Lloyd Zusman           01234567 <-- The world famous Indent-o-Meter.
 l...@panix.com          ^       I indent thee.
   To get my PGP public key automatically mailed to you, please
   send me email with the following string as the subject or on a
   line by itself in the message (leave off the quotation marks):
                    "mail-request public-key"



 Mon, 01 Dec 1997 03:00:00 GMT   
 
   [ 5 post ] 

Similar Threads

1. need help for "foreach/csh"

2. Help to find a good book on csh/tcsh to teach myself csh/tcsh script

3. how to call csh scripts from inside other csh scripts

4. csh question: foreach

5. csh foreach ( ` cat file ` ) question

6. csh - foreach command

7. csh foreach question

8. csh question: foreach

9. foreach word/var limitation in csh

10. csh, foreach, and ctrl-Z oddity


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software