Re: Shell Expansion in Bourne Shell Script Question

2010-07-30 Thread Chris Davies
Karl Vogel wrote: > for file in $(ls $MAGDIR/*.[Zz][Ii][Pp] 2> /dev/null); do ... mkdir $MAGDIR/silly.zip touch $MAGDIR/silly.zip/not-a-zip-file If you're going to insist on using "ls" you should consider "ls -d". Personally, I'd still go for this construct: for FILE in "$MAGDIR"/*.[

Re: Shell Expansion in Bourne Shell Script Question

2010-07-29 Thread Boyd Stephen Smith Jr.
On Thursday 29 July 2010 05:27:35 Mart Frauenlob wrote: > On 29.07.2010 07:17, Boyd Stephen Smith Jr. wrote: > > On Wednesday 28 July 2010 21:37:44 Karl Vogel wrote: > >> I need to think before posting. I didn't mention that I have > >> FreeBSD, Linux, and Solaris boxes, and unfortunately

Re: Shell Expansion in Bourne Shell Script Question

2010-07-29 Thread Mart Frauenlob
On 29.07.2010 07:17, Boyd Stephen Smith Jr. wrote: On Wednesday 28 July 2010 21:37:44 Karl Vogel wrote: On Thu, 29 Jul 2010 01:04:27 -, Cameron Hutchison said: C> find $MAGDIR -iname '*.zip' -print0 | xargs -0 some-command C> -iname matches names case insensitively. Since you then

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Boyd Stephen Smith Jr.
On Wednesday 28 July 2010 21:37:44 Karl Vogel wrote: > >> On Thu, 29 Jul 2010 01:04:27 -, > > >> Cameron Hutchison said: > C>find $MAGDIR -iname '*.zip' -print0 | xargs -0 some-command > C> -iname matches names case insensitively. Since you then dont need grep, > C> you also dont need tr0

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Boyd Stephen Smith Jr.
On Wednesday 28 July 2010 13:05:22 Karl Vogel wrote: > >> On 28.07.2010 14:42, Jochen Schulz wrote: > J> I think you meant to write > J> for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]` > J> Another hint: you don't need 'ls' for your case at all. > >I'd recommend keeping the "ls". Then, you wou

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Karl Vogel
>> On Thu, 29 Jul 2010 01:04:27 -, >> Cameron Hutchison said: C>find $MAGDIR -iname '*.zip' -print0 | xargs -0 some-command C> -iname matches names case insensitively. Since you then dont need grep, C> you also dont need tr0. I need to think before posting. I didn't mention that I h

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Cameron Hutchison
vogelke+deb...@pobox.com (Karl Vogel) writes: >>> On Wed, 28 Jul 2010 23:58:11 +0200, >>> Mart Frauenlob said: >M> One might be better of with some like this: >M> find /DIR -regextype posix-egrep -regex '.*\.(zip|ZIP)' -exec \ >M> some_command {} + > If the filelist is potentially too

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Karl Vogel
>> On Wed, 28 Jul 2010 23:58:11 +0200, >> Mart Frauenlob said: M> One might be better of with some like this: M> find /DIR -regextype posix-egrep -regex '.*\.(zip|ZIP)' -exec \ M> some_command {} + If the filelist is potentially too big for the max argument list on the system, I wou

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Mart Frauenlob
On 28.07.2010 20:05, Karl Vogel wrote: On 28.07.2010 14:42, Jochen Schulz wrote: J> I think you meant to write J> for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]` J> Another hint: you don't need 'ls' for your case at all. I'd recommend keeping the "ls". Try your script when MAGDIR doesn'

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Karl Vogel
>> On 28.07.2010 14:42, Jochen Schulz wrote: J> I think you meant to write J> for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]` J> Another hint: you don't need 'ls' for your case at all. I'd recommend keeping the "ls". Try your script when MAGDIR doesn't have any zipfiles, and MAGFILE will ho

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Christian Jaeger
> for MAGFILE in $MAGDIR/*.zip Don't forget the double quotes around variable references. It's better to always do that by default than to fix it afterwards (either because you feed it paths with whitespace in them yourself at some point or because someone else is trying to close the safety holes

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Clive Standbridge
> for MAGFILE in `ls *.[Zz][Ii][Pp] $MAGDIR/`; do > #lots of other stuff > done As others noted, the ls command is superfluous and possibly harmful here. One more thing you can do is case-insensitive pathname expansion: shopt -s nocaseglob for MAGFILE in $MAGDIR/*.zip do #lots of other

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Paul E Condon
On 20100728_082732, Martin McCormick wrote: > Cesar Garcia writes: > > Perhaps, try with this: > > > > for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]`; do It probably doesn't really matter in practice, but this will pick up also files that match $MAGDIR/*.zIp , etc. (mixed case) To avoid getting the

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Mart Frauenlob
On 28.07.2010 14:42, Jochen Schulz wrote: Martin McCormick: ls *.[Zz][Ii][Pp] Note that 'ls' doesn't see this pattern at all. The pattern is expanded by the shell to all existing files matching the pattern. This list of files is then passed to ls. Using 'echo' would yield (almost) the same re

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Martin McCormick
Cesar Garcia writes: > Perhaps, try with this: > > for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]`; do That worked. Thank you. As soon as I saw the example, I realized that in the script, there was no way for it to know where these files were that I was looking for. Also my thanks to

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Jochen Schulz
Martin McCormick: > > ls *.[Zz][Ii][Pp] Note that 'ls' doesn't see this pattern at all. The pattern is expanded by the shell to all existing files matching the pattern. This list of files is then passed to ls. Using 'echo' would yield (almost) the same result in this case. > for MAGFILE in

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Jordon Bedwell
On 7/28/10 7:06 AM, Jordon Bedwell wrote: #!/bin/sh for MAGFILE in $(ls *\.[zZ][iI][pP]) do echo "File: $MAGFILE"; done I would prefer to rely on $() before `` in a bash script. Sorry, I did that script on OS X, you should switch the SH shebang to Bash, it's just aliased on OS X but not on

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Jordon Bedwell
On 7/28/10 6:33 AM, Martin McCormick wrote: I could have sworn I have done this before but obviously not because I can't get it to work no matter what I try. I am running a shell script that is supposed to find every .zip or .ZIP file in a directory and do an extraction of the co

Re: Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Cesar Garcia
Perhaps, try with this: for MAGFILE in `ls $MAGDIR/*.[Zz][Ii][Pp]`; do El 28/07/10 13:33, Martin McCormick escribió: > I could have sworn I have done this before but obviously > not because I can't get it to work no matter what I try. > > I am running a shell script that is suppos

Shell Expansion in Bourne Shell Script Question

2010-07-28 Thread Martin McCormick
I could have sworn I have done this before but obviously not because I can't get it to work no matter what I try. I am running a shell script that is supposed to find every .zip or .ZIP file in a directory and do an extraction of the contents. I don't want any other files to be inc