title: PlistBuddy - adding array items works in terminal but not in bash script
body: <p>I try to manipulate my Info.plist file using <code>plistbuddy</code> by adding custom fonts array field by script. The commands execute successfully in terminal (both: array entry is created and entries are added):</p>
  
  <pre><code>luka$ /usr/libexec/PlistBuddy testing.plist
  File Doesn't Exist, Will Create: testing.plist
  Command: Add UIAppFonts array
  Command: Add UIAppFonts: string test
  Command: Add UIAppFonts: string Test2
  Command: Save
  Saving...
  </code></pre>
  
  <p><strong>This produces nice plist file, as expected:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;dict&gt;
      &lt;key&gt;UIAppFonts&lt;/key&gt;
      &lt;array&gt;
          &lt;string&gt;test&lt;/string&gt;
          &lt;string&gt;Test2&lt;/string&gt;
      &lt;/array&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>But the same commands fail while executing in bash script (<code>test.sh</code>):</p>
  
  <pre><code>#! /bin/bash
  PLISTBUDDY="/usr/libexec/PlistBuddy -c"
  FILE="./test.plist"
  $PLISTBUDDY "Add UIAppFonts array" $FILE
  FF_CUSTOM_FONTS="Font_a.otf,Font_b.otf"
  set -f; IFS=,
      FONT_INDEX=0
      for CUSTOM_FONT in $FF_CUSTOM_FONTS
          do
              PLIST_COMMAND="Add UIAppFonts: string $CUSTOM_FONT"
              echo "executing: $PLIST_COMMAND"
              $PLISTBUDDY $PLIST_COMMAND $FILE
              FONT_INDEX=$((FONT_INDEX+1))
          done
  set =f; unset IFS
  </code></pre>
  
  <p>In this case, only array is created, but adding entries fail. I only get not that much descriptive error:</p>
  
  <pre><code>luka$ ./test.sh
  File Doesn't Exist, Will Create: ./test.plist
  executing: Add UIAppFonts: string Font_a.otf
  ./test.sh: line 12: /usr/libexec/PlistBuddy -c: No such file or directory
  executing: Add UIAppFonts: string Font_b.otf
  ./test.sh: line 12: /usr/libexec/PlistBuddy -c: No such file or directory
  </code></pre>
  
  <p><strong>Produces this (only array, no entries):</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;dict&gt;
      &lt;key&gt;UIAppFonts&lt;/key&gt;
      &lt;array/&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>Why does that happen and why only with commands adding entries to an array?I use <code>plistbuddy</code> in many other places (in bash scripts) and commands like setting, adding and deleting simple fields all work just fine.</p>
  
  <p>I am not that good in scripting, so most probably I am missing some kind of escaping or other bash specific detail.</p>