Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to feed the Application directory into an array and then use PlistBuddy with the entries to retrieve version info about each application that are installed. Currently it seems to be not separating the list into individual array entries.

    apps=$(ls /Applications)
        for i in "$apps"
                 /usr/libexec/plistbuddy -c Print:CFBundleShortVersionString: "$i"/Contents/info.plist
share|improve this question
up vote 3 down vote accepted

That's because you are not creating an array. apps is a string that contains the result of ls /Applications. Anyway, you don't need the ls, try something like this:

for i in /Applications/*
  /usr/libexec/plistbuddy -c Print:CFBundleShortVersionString: "$i"/Contents/Info.plist
share|improve this answer
Isn't info.plist usually written with uppercase I? – Daniel Beck Apr 1 '13 at 20:12
@DanielBeck thanks, fixed. I don't have a Mac so I just copied directly from the OP's question – terdon Apr 2 '13 at 14:59

Some applications didn't have a CFBundleShortVersionString key. You could also use defaults or search for applications with mdfind:

IFS=$'\n'; for f in $(mdfind; do printf %s "${f##*/}:"; defaults read "$f/Contents/Info.plist" CFBundleShortVersionString 2> /dev/null || defaults read "$f/Contents/Info.plist" CFBundleVersion 2> /dev/null || echo; done

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .