[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell Expansion in Bourne Shell Script Question



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@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


Reply to: