15

I have a somewhat complex bash command which includes some pipes and an if-then-else clause, not to mention calling system program (such as grep) with multiple parameters.

Is there a way to create a plist that launchd will load and run this complex command directly? (As opposed to having the plist reference a bash script file containing the complex command)

Thanks.

UrEl
  • 891

1 Answers1

19

Yes. When setting up the ProgramArguments element, simply use bash as the first argument, -c as the second argument, then [your commands] (remembering to replace any XML entities, such as >, & and so on) as the third, like so:

<key>ProgramArguments</key>
<array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>ls -1 | grep *.txt | echo &gt; allTextFiles</string>
</array>

Replace the third element of the array with your actual command.

Daniel Beck
  • 111,893
Scott
  • 5,993