Re: [dev] [query] A tool for filtering lists of filenames with return codes

From: Eric Pruitt <eric.pruitt_AT_gmail.com>
Date: Fri, 20 May 2016 07:47:42 -0700

On Fri, May 20, 2016 at 07:29:28AM -0700, Evan Gates wrote:
> This ability is already built in to find using the -exec primary. And
> newline delimited lists of files are not safe. If the program you are
> piping to supports nul delimited lists you can print them in POSIX
> find by doing

I know using newlines isn't safe, and that's why the tool supports a -0
flag for null-delimited fields. Newline mode is the default since most
other *nix tools assume line or whitespace delimation; principle of
least surprise.

>
> For your first example
>
> find . -type f -exec sh -c 'ldd "$1" >/dev/null 2>&1' sh {} \; -print
>
> or better, yet, fewer instances of sh
>
> find . -type f -exec sh -c 'for f do ldd "$f" >/dev/null 2>&1 &&
> printf %s\\n "$f"; done;:' sh {} +
>
> These examples do just print the filenames, so they are for visual
> inspection only. If you want to do something with those filenames, do
> so in exec, or print them with nul delimiters (but really... just
> -exec).

Yes, it is certainly possible to achieve what this tool does by other
means. This program actually started out as a shell script that looked
something like this:

    while read line; do
        if cat -- "$line" | "$_AT_" > /dev/null; then
            echo "$line"
        fi
    done

I wanted something more robust, and I opted to write the tool in C
because it's fast and my C skills have been getting pretty rusty.

Thanks for the feedback,
Eric
Received on Fri May 20 2016 - 16:47:42 CEST

This archive was generated by hypermail 2.3.0 : Fri May 20 2016 - 17:00:05 CEST