help: for file in *

help: for file in *

Post by Andrew Levandosk » Thu, 07 Oct 1999 04:00:00



I would like to do the following below.  But instead of the * you see, I
would
like the user to have to option to specify a pattern such as (*.c) or
(pattern.*).
So I tried to accept this parameter using a $1 instead of the *.  No
luck
though.  It would only pull in the first file that met the criteria and
no others...

for file in *
do
      blah blah
done

Any input is greatly appreciated!

 
 
 

help: for file in *

Post by Barry Margoli » Thu, 07 Oct 1999 04:00:00




Quote:>I would like to do the following below.  But instead of the * you see, I
>would
>like the user to have to option to specify a pattern such as (*.c) or
>(pattern.*).
>So I tried to accept this parameter using a $1 instead of the *.  No
>luck
>though.  It would only pull in the first file that met the criteria and
>no others...

>for file in *
>do
>      blah blah
>done

Wildcards are expanded by the user's shell before it invokes the script.
So if he types

scriptname *.c

it will act as if he had typed

scriptname file1.c file2.c file3.c ...

You should use


to get all the filenames that the wildcard expanded to.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

help: for file in *

Post by Andrew Levandosk » Thu, 07 Oct 1999 04:00:00



run the grep command on thousands of files in one directory.
Since grep only accepts upto 1000 input files at a time, I was
trying to build a filelist of a thousand files and execute the grep
when the filelist has a thousand files in it or there are no more
input files left.


Thanks for the help,
Andrew

> Wildcards are expanded by the user's shell before it invokes the script.
> So if he types

> scriptname *.c

> it will act as if he had typed

> scriptname file1.c file2.c file3.c ...

> You should use


> to get all the filenames that the wildcard expanded to.

> --

> GTE Internetworking, Powered by BBN, Burlington, MA

 
 
 

help: for file in *

Post by chris ulri » Thu, 07 Oct 1999 04:00:00





>run the grep command on thousands of files in one directory.
>Since grep only accepts upto 1000 input files at a time, I was
>trying to build a filelist of a thousand files and execute the grep
>when the filelist has a thousand files in it or there are no more
>input files left.


>Thanks for the help,
>Andrew

  You've got problems.
  You only see that message if you have more arguments on the command
line than your unix kernel can deal with.  So, for example, when you
type
foo *c
where foo is the name of your program, your shell expands *c to be
a list of all the files in that directory named (anything ending in c).

  You can get around this by passing the wild card to the shell un-expanded.
You can only do this by reading the wild card after the shell has started,
something like

echo "what files do you wish to match? \n"
read files

for list in $files
do
 ..
done
exit 0
  It is important that you *not* quote the variable in the for loop.
This will (should) work because the shell never tries to pass the
huge list of arguments to another program, so it never triggers the
kernel limit.
chris

 
 
 

help: for file in *

Post by Jim Harri » Fri, 08 Oct 1999 04:00:00


How about:

ls *.c | while read file
do
grep ${grepexp} ${file}
done



> run the grep command on thousands of files in one directory.
> Since grep only accepts upto 1000 input files at a time, I was
> trying to build a filelist of a thousand files and execute the grep
> when the filelist has a thousand files in it or there are no more
> input files left.


> Thanks for the help,
> Andrew

> > Wildcards are expanded by the user's shell before it invokes the script.
> > So if he types

> > scriptname *.c

> > it will act as if he had typed

> > scriptname file1.c file2.c file3.c ...

> > You should use


> > to get all the filenames that the wildcard expanded to.

> > --

> > GTE Internetworking, Powered by BBN, Burlington, MA

 
 
 

help: for file in *

Post by Ken Pizzi » Fri, 08 Oct 1999 04:00:00





>> run the grep command on thousands of files in one directory.
>> Since grep only accepts upto 1000 input files at a time, I was
>> trying to build a filelist of a thousand files and execute the grep
>> when the filelist has a thousand files in it or there are no more
>> input files left.


>How about:

>ls *.c | while read file
>do
>grep ${grepexp} ${file}
>done

Doesn't help --- the "ls *.c" will blow up with the "parameter
list too long" error.  But you could change that to:
  ls | while read file
  do
  case $file in *.c) grep ${grepexp} ${file} ;; esac
  done

                --Ken Pizzini

 
 
 

1. Netscape plug-ins, helper files, Acrobat etc.

What I want is a way of preventing users downloading their own plug-ins,
helper programs and so on.  Any ideas?  :-(

Now that we have all had a good laugh, I have more serious questions:

    1) Is there any good reason either to install the standard null
plug-in, or not to install it?  Netscape seems to work without it.
As you might expect, there is no documentation on what it does or (more
likely) doesn't do.

    2) Does either Netscape or Acrobat allow users to fire up a local
executable?  I am wondering whether using chroot and setting PATH to
something unhelpful is worthwhile.

[ Oh, my solution to the user-loaded plug-in problem is a threat of
public disembowelment, and a cron job that checks for the damn things
and logs the offence and clobbers the file.  NOT the right solution. ]

Nick Maclaren,
University of Cambridge Computer Laboratory,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.

Tel.:  +44 1223 334761    Fax:  +44 1223 334679

2. Best OS for Internet server on Pentium ? Linux, NT, Solaris, SCO ?

3. Compare file modification date using tcsh built-ins

4. Introduction to X programming

5. Need HELP to Log User Log-ins form the internet

6. console going blank

7. Netscape helpers and plug-ins, also java help

8. Acer "Aopen" P53 motherboard and USB ???

9. HELP WITH DIAL INS

10. Need Help on setting up getty for dial-ins

11. New HOWTO....HOWTO-Hose-RedHat-Installation (help!)

12. In search of Solaris 2.5 Netscape Navigator 3.0 plug ins

13. Suse 7.0; Yast2, kinternet, rc.dialout und ich komme nicht ins Internet