简体   繁体   中英

Pass stdin to plistbuddy

I have a script to show the content of the Info.plist of .ipa files:

myTmpDir=`mktemp -d 2>/dev/null || mktemp -d -t 'myTmpDir'`
unzip -q "$1" -d "${myTmpDir}";
pathToFile=${myTmpDir}/Payload/*.app/Info.plist
/usr/libexec/PlistBuddy -c "Print" ${pathToFile}

With large files this can take some time until they are extracted to the temp folder just to read a small Info.plist (xml) file. I wondered if I can just extract Info.plist file and pass that to plistbuddy? I've tried:

/usr/libexec/PlistBuddy -c "Print" /dev/stdin <<< \
$(unzip -qp test.ipa Payload/*.app/Info.plist)

but this yields

Unexpected character b at line 1
Error Reading File: /dev/stdin

The extraction is working fine. When running unzip -qp test.ipa Payload/*.app/Info.plist I get the output of the Info.plist file to the terminal:

$ unzip -qp test.ipa Payload/*.app/Info.plist
bplist00?&


!"#$%&'()*+5:;*<=>?ABCDECFGHIJKXYjmwxyIN}~N_BuildMachineOSBuild_CFBundleDevelopm...

How can I pass the content of the Info.plist to plistbuddy?

Usually commands support "-" as a synonym of stdin, but this PlistBuddy tool doesn't.

But you can still extract just one file from your ipa, save it as a temporary file, and then run PlistBuddy on that file:

tempPlist="$(mktemp)"
unzip -qp test.ipa "Payload/*.app/Info.plist" > "$tempPlist"
/usr/libexec/PlistBuddy -c Print "$tempPlist"
rm "$tempPlist"

我最终得到了chepner建议的plutil:

unzip -qp test.ipa Payload/*.app/Info.plist | plutil  -convert xml1 -r -o - -- -

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM