help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] script help please


From: Greg Wooledge
Subject: Re: [Help-bash] script help please
Date: Thu, 25 Jun 2015 11:36:05 -0400
User-agent: Mutt/1.4.2.3i

On Thu, Jun 25, 2015 at 10:38:27AM -0400, Randy wrote:
>    There is a command I use frequently:
>    find *.pdf -exec sh -c 'pdftotext "{}" - | grep --with-filename
>    --label="{}" --color "XXXX"' \;

Note that this does not actually recurse.  It only "finds" PDF files
in the current directory.

You also have potential code injection exploits here, if it is run in
a directory that has malicious filenames.  It's not safe to embed the
{} directly inside a shell script.  The filenames will become part of
the script.

>    (where "XXXX" is the text for which I am search PDF files.)
>    I tried to write a script, where I could simply pass-in ($1) the
>    string.  Could not make it work.

# Usage: pdfgrep searchtext
pdfgrep() {
    find . -type f -name '*.pdf' -exec sh -c '
        pdftotext "$2" - |
        grep -F --with-filename --label="$2" --color "$1"
    ' _ "$1" {} \;
}

That version recurses.  You're apparently using some GNU utilities, so
if you didn't actually want the recursion, you could add a -maxdepth
option.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]