title: How to use PlistBuddy using command substiution
body: <p>I am trying the following script</p>
  
  <pre><code>#!/bin/bash
  
  OUTPUT="$(cat /Users/admin/Desktop/plist-script-output/keys-updated.txt | sed 's/"//g; s/^/-c "Print :/g; s/$/"/g' | tr '\n' ' ')"
  
  FILE="/Users/admin/Desktop/plist-script-output/plist-data/data.plist"
  
  PLISTBUDDY=$(/usr/libexec/PlistBuddy $OUTPUT $FILE 2&gt;&amp;1)
  echo "$PLISTBUDDY"
  </code></pre>
  
  <p>The output of the above script is <strong>Unrecognized Command</strong></p>
  
  <p>The value of OUTPUT variable is </p>
  
  <p>-c "Print :Ant-Conversion" -c "Print :Newitem" -c "Print :Area" -c "Print :Contact"</p>
  
  <p><strong>2>&amp;1</strong> this is added so as to print both the errors (does not exist keys) and proper output.</p>
  
  <p>The <strong>keys-updated.txt</strong> contains the list of keys to be extracted from the plist files (not necessary all are present in the plist)</p>
  
  <h2>SOLUTION (NOT WORKING)</h2>
  
  <p>Tried the solution from @Nahuel. however the line </p>
  
  <p><strong>PLISTBUDDY=$(eval set -- $OUTPUT;/usr/libexec/PlistBuddy "$@" "$FILE")</strong></p>
  
  <p>provides only the <strong>list of keys which do not exist in the plist</strong></p>
  
  <p>This is the output I am receiving after using the solution from @Nahuel</p>
  
  <p>Print: Entry, "Status", Does Not Exist</p>
  
  <p>Print: Entry, "Notify", Does Not Exist</p>
  
  <p>Print: Entry, "IsMvnMgrSupported", Does Not Exist</p>
  
  <p>Print: Entry, "BuildsetFile", Does Not Exist</p>
  
  <p>Print: Entry, "RollupClocReportToModule", Does Not Exist</p>
  
  <p>Print: Entry, "Branches", Does Not Exist</p>
  
  <p>Print: Entry, "Ant-Conversion", Does Not Exist</p>
  
  <p>Print: Entry, "IndexTag", Does Not Exist</p>
  
  <p>Print: Entry, "WO", Does Not Exist</p>
  
  <p>Print: Entry, "Tags", Does Not Exist</p>
  
  <p>Print: Entry, "Newitem", Does Not Exist</p>
  
  <p>ON USING THE COMMAND DIRECTLY ON COMMAND LINE</p>
  
  <p><strong>admin:Desktop admin$</strong> . 
  <strong>/usr/libexec/PlistBuddy -c "Print :Area" -c "Print :Contact" -c "Print :Email" -c "Print :Language" -c "Print :Location" -c "Print :Name" -c "Print :Notes" -c "Print :Purpose" -c "Print :Track" -c "Print :Type" -c "Print :URL" -c "Print :Status" -c "Print :Notify" -c "Print :IsMvnMgrSupported" -c "Print :BuildsetFile" -c "Print :RollupClocReportToModule" -c "Print :Branches" -c "Print :Ant-Conversion" -c "Print :IndexTag" -c "Print :WO" -c "Print :Tags" -c "Print :Newitem" /Users/admin/Desktop/plist-script-output/plist-data/ActiveMQ.plist</strong></p>
  
  <p>The output turns out to be </p>
  
  <p><strong>Monitoring . 
  cucducheuneun . 
  cdcdcdcdc . 
  Java . 
  dvfvfvfvfvfvfv . 
  ActiveMQ . 
  cddcdcdcdc . 
  An messaging (JMS) framework from the Apache Software Foundation.<br>
  Infrastructure . 
  Framework . 
  jdbcjdbcdjdcnnjn . 
  Print: Entry, ":Status", Does Not Exist . 
  Print: Entry, ":Notify", Does Not Exist . 
  Print: Entry, ":IsMvnMgrSupported", Does Not Exist . 
  Print: Entry, ":BuildsetFile", Does Not Exist . 
  Print: Entry, ":RollupClocReportToModule", Does Not Exist . 
  Print: Entry, ":Branches", Does Not Exist . 
  Print: Entry, ":Ant-Conversion", Does Not Exist . 
  Print: Entry, ":IndexTag", Does Not Exist . 
  Print: Entry, ":WO", Does Not Exist . 
  Print: Entry, ":Tags", Does Not Exist . 
  Print: Entry, ":Newitem", Does Not Exist . 
  Abort trap: 6</strong>  </p>