David,
It is great to have the "canonical" "right" way to do it.
(I mean that, I am in the process of moving some work flows for my
office from Windows GUI apps to Linux CLI tools, so I want the result
to be as robust as I can get it.)
For me the script's speed is trivial. ie. Each ewfverify takes on the
order of hours to complete, so the number of 10's of second it
requires to launch is lost in the noise.
Greg
On Wed, Feb 27, 2013 at 12:39 AM, David Haller
Hello,
On Mon, 25 Feb 2013, Greg Freemyer wrote:
In non-working-psuedo-find-language I want to find a command to do:
find . -name \*.E01 -exec ewfverify -l $(basename '{}').ewfverify.out '{}' ;
Can anyone give me the right syntax. I'm not sure if it is easier to add xargs to the mix, if so that's fine too.
The "canonical" "right" way is like this:
find . -name '*.E01' -exec bash -c ' ewfverify -l "$(basename "$1").ewfverify.out" "$1" ' find-bash -- '{}' ';'
The syntax behind the -exec is: /bin/bash # shell to call, here 'sh' # other shell option[s], here none -c 'script' # option '-c' + script find-bash # argument $0 for the script, you'll see # that 'find-bash' in a 'ps' output -- # end of sh-options '{}' # argument[s] for the script after -c [;+] # end marker for find
Alternatively one can use with BSD-find and newer GNU-find:
find . -name '*.E01' -exec bash -c ' for file; do ewfverify -l "$(basename "$file").ewfverify.out" "$file" done ' find-bash -- '{}' '+'
(assuming that starting the shell dominates the execution, if the work that'd go inside the for-file-loop dominates the work it's little relevant as seems to be in your case).
Both above solutions are (mostly) portable and robust regarding filenames etc. as long as you write your script(-fragment) robust (and portable), i.e. above should not have problems with any legal filenames, e.g. linebreaks should not be any problem. Haven't tested it recently though.
Instead of 'sh -c SCRIPT' you can use a saved script to ease quoting.
-exec ewfverify-wrapper '{}' '+'
with ewfverify-wrapper being in your PATH (e.g. ~/bin/) and containing:
==== ~/bin/ewfverify-wrapper ==== #!/bin/bash for file; do ewfverify -l "$(basename "$file").ewfverify.out" "$file" done ====
or whatever needs to be done. E.g. calling 'awk' or other stuff that one likes to use '' for quoting with from inside a 'sh -c' is extremely yucky, a sh -c 'awk -F '\''/'\'' '\''{printf("%s\n", $NF);}'\''' is just the start of it.
HTH, -dnh
-- Life sucks, and then you die. And then it still sucks. -- Georgia 'George' Lass, Dead Like Me -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org