Get Array of Values using plistBuddy Get Array of Values using plistBuddy shell shell

Get Array of Values using plistBuddy


It seems PlistBuddy produces output like this:

Array {    ABCD.com.bus.NoEntitlements    ABCD.com.bus.sharing}

That is, multiple lines. If you want to get to the elements of the Array, you need to first slice off the first and last lines:

/usr/libexec/PlistBuddy | sed -e 1d -e '$d'

Next, to read this into a Bash array, you need to surround the $(...) subshell with another (...), like this:

declare -a val=($(/usr/libexec/PlistBuddy | sed -e 1d -e '$d'))

After this, you can access the first value with ${val[0]} and the second value with ${val[1]}.