Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
build array with brace expansion per Allister's recomendation
#!/bin/bash
# build array with brace expansion per Allister's recomendation
array=(/Applications/{GarageBand,Pages,iMovie,iPhoto,Keynote,Numbers}.app)
for path in "${array[@]}"; do
app_name="${path##*/}"
name="${app_name%.*}"
version=$(defaults read "${path}"/Contents/Info CFBundleShortVersionString)
pkgbuild --component "${path}" $HOME/Desktop/"${name}-${version}".pkg
done

If this were code golf...
array=(/Applications/{GarageBand,Pages,iMovie,iPhoto,Keynote,Numbers}.app) can generate multiple lines with the 'prefix' and 'suffix' you need...

Owner

rmanly commented Apr 25, 2014

Ah yes!

Well done. :)

In the original I was using iTerm interactively and just dragged them into place. This is much better for the full script and I probably would not have thought to use brace expansion for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment