From: Mart Frauenlob on
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't
> have any zipfiles, and MAGFILE will hold the expanded value of $MAGDIR
> with the string "*.[Zz][Ii][Pp]" appended. Bash, sh, and ksh all do
> that for some dopey reason, which is why I would do
>
> for file in $(ls $MAGDIR/*.[Zz][Ii][Pp] 2> /dev/null); do ...
>
> if there's any chance that you won't find any files.
>

Now that's an odd one! Didn't know that.
One might be better of with some like this:

find /DIR -regextype posix-egrep -regex '.*\.(zip|ZIP)' -exec
some_command {} +


Best regards

Mart


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4C50A7F3.9040502(a)chello.at
From: Cameron Hutchison on
vogelke+debian(a)pobox.com (Karl Vogel) writes:

>>> On Wed, 28 Jul 2010 23:58:11 +0200,
>>> Mart Frauenlob <mart.frauenlob(a)chello.at> 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 would do something like this:

> find $MAGDIR -print | grep -i '\.zip$' | tr0 | xargs -0 some command

find $MAGDIR -iname '*.zip' -print0 | xargs -0 some-command

-iname matches names case insensitively. Since you then dont need grep,
you also dont need tr0.



--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/788e.4c50d39b.7c987(a)getafix.xdna.net
From: Karl Vogel on
>> On Thu, 29 Jul 2010 01:04:27 -0000,
>> Cameron Hutchison <lists(a)xdna.net> 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 have FreeBSD,
Linux, and Solaris boxes, and unfortunately I can't guarantee the same
access to GNU find. I can install xargs if the system version doesn't
recognize the "-0" option, so I usually end up scripting for the lowest
common denominator.

--
Karl Vogel I don't speak for the USAF or my company

Cute Celebrity Couple Names #6:
Lance Armstrong + Ivanka Trump = Armstump


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/20100729023745.D8A58BED9(a)kev.msw.wpafb.af.mil
From: Boyd Stephen Smith Jr. on
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 would be wrong. Doing the splitting on the output of ls causes IFS
characters in file names to be handled incorrectly:

bss(a)dellbuntu:/tmp% touch 'file with spaces'
bss(a)dellbuntu:/tmp% for f in `ls -d *`; do echo file; done | wc -l
9
bss(a)dellbuntu:/tmp% for f in *; do echo file; done | wc -l
7
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
bss(a)iguanasuicide.net ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
From: Mart Frauenlob on
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 -0000,
>>
>>>> Cameron Hutchison<lists(a)xdna.net> 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 have FreeBSD,
>> Linux, and Solaris boxes, and unfortunately I can't guarantee the same
>> access to GNU find. I can install xargs if the system version doesn't
>> recognize the "-0" option, so I usually end up scripting for the lowest
>> common denominator.
>
> In that case, you'll have to be very careful in order to handled file names
> that contain IFS characters or newlines:
>
> find "$MAGDIR" -name "*.[zZ][iI][pP]" -exec \
> sh -c 'handle_single_file "$1"' ignored {} \;
>
> That will work on any POSIX system, or most systems with POSIX-conforming find
> and sh. You *may* have to specify full paths to the POSIX-conforming find and
> sh commands.


yes, '-exec command {} +' is also POSIX, but newer (collects argument
list similar to xargs).
What I've been reading on a recent discussion on de.comp.os.unix.shell
-print0 is about of equal age, so about an equal chance to have one or
the other feature available.
I think using '-type f' would not be wrong either, as otherwise we would
match directories also.

Best regards

Mart


--
To UNSUBSCRIBE, email to debian-user-REQUEST(a)lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster(a)lists.debian.org
Archive: http://lists.debian.org/4C515797.7070809(a)chello.at