Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
1  
I haven't tested this, but I'm pretty sure you don't want quotes around the command string, but that you do need to html-entity encode it (e.g. use &gt; and &lt; instead of > and < for redirections). –  Gordon Davisson May 18 '11 at 17:03
    
Thanks to you both –  UrEl May 18 '11 at 17:28
    
@Gordon Davisson - you're certainly right about the quotes - they serve the same purpose as making it one element of the array. I'm pretty sure you're right about the XML entities, too. Good catch. I've edited my answer accordingly. –  Scott May 18 '11 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.