0

The following works fine when I type it exactly in the command line:

find /<some_path>/{epson,epson_laser,epson_inkjet} -iname "*.ppd" 
  -exec grep "\*ModelName\:" {} \; | sed 's/.*\"\(.*\)\"/\1/'

However, when I try to call the following from a bash script I get find: missing argument to -exec'.

I have also tried the following (in many variants):

eval find "$1" -iname "*.ppd" -exec 'bash -c grep "\*ModelName\:" "$1" | sed "s/.*\"\(.*\)\"/\1/" \;

as was mentioned in find-exec-echo-missing-argument-to-exec. How can I get to work first code not only in terminal, but also in bash script?

P.S.: I've used eval only for expanding string "/<some_path>/{epson,epson_laser,epson_inkjet}" to multiple paths. Does anyone know better solution for doing this?

Community
  • 1
  • 1
Mephi_stofel
  • 355
  • 2
  • 6
  • 15
  • That error means that the `\;` argument isn't being seen, but it looks fine to me above. Please paste the exact `find` line from your script. – Barmar Dec 20 '12 at 11:01
  • Well, doesn't matter which `find` line in script as no one works ;) But how to get the same result as in the first line I typed, but get it to work in bash script? the first line work when I type it directly to terminal, but in bash it in any combination doesn't work. – Mephi_stofel Dec 20 '12 at 11:10
  • 1
    When you use `eval` you have to double up the escapes. The first one escapes the character for the original shell, the second one escapes it for `eval`. – Barmar Dec 20 '12 at 11:12
  • That's why it's better to put the `-exec` command into a script, so you don't need to use `eval`. – Barmar Dec 20 '12 at 11:13
  • 1
    Actually, I'm not sure why you need to use `eval` in the first place. – Barmar Dec 20 '12 at 11:14
  • Maybe you should also tell us what you're really trying to achieve. We could find the best approach to your problem. – gniourf_gniourf Dec 20 '12 at 12:14

1 Answers1

0

If you want to execute multiple commands over the output of find, just use the -exec options as many times required:

find -exec command1 "{}" \; -exec command2 "{}" \;

You can also define the conditions to execute an option:

find \( -exec command1 \; -false -o -exec command2 \; \)

In your case, you need something like this:

find /<some_path>/{epson,epson_laser,epson_inkjet} -iname "*.ppd" -exec grep "\*ModelName\:" "{}" \;  sed 's/.*\"\(.*\)\"/\1/' "{}" \;