title: Iterate an array in a shell script to save its values in a .plist and a .db
body: <p>This shell script allows to programmatically save text replacements for macOS, on both <code>GlobalPreferences.plist</code> and <code>UserDictionary.db</code>.</p>
  
  <pre><code>date=$(date +%s)
  while read -r replace with; do
      plist+="{on=1;replace=\"$replace\";with=\"$with\";},"
      sql+="INSERT INTO 'ZUSERDICTIONARYENTRY' VALUES($((++i)),1,1,0,0,0,0,$date,NULL,NULL,NULL,NULL,NULL,\"$with\",\"$replace\",NULL);"
  done &lt; &lt;(sed 's/\\/\\\\/g;s/"/\\"/g' ~/replacements.txt)
  sqlite3 ~/Library/Dictionaries/CoreDataUbiquitySupport/$USER~*/UserDictionary/local/store/UserDictionary.db "delete from ZUSERDICTIONARYENTRY;$sql"
  defaults write -g NSUserDictionaryReplacementItems "(${plist%?})"
  </code></pre>
  
  <p>How can I customize it so that it can read a previously declared array, instead of a <code>~/replacements.txt</code> external file?</p>