Ios 正在从plutil获取信息

Ios 正在从plutil获取信息,ios,bash,shell,Ios,Bash,Shell,我无法从plutil获得方向信息。我想检查.plist是否包含键CbundleShortVersionString。我不认为plutil有任何选项可以测试密钥是否存在,所以我想我只需要plutil-show file.plist>file.txt,但这样做不起作用。:/因此,我尝试使用dump选项plutil-dump file.plist>file.txt将plist文件从stdout引导到另一个文件,但没有成功:我还尝试将stdout定向到stderr和stderr,并将stdout定向到文

我无法从plutil获得方向信息。我想检查.plist是否包含键CbundleShortVersionString。我不认为plutil有任何选项可以测试密钥是否存在,所以我想我只需要
plutil-show file.plist>file.txt
,但这样做不起作用。:/因此,我尝试使用dump选项
plutil-dump file.plist>file.txt将plist文件从stdout引导到另一个文件,但没有成功:我还尝试将stdout定向到stderr和stderr,并将stdout定向到文件。什么都没用。如何执行此操作?

如果需要测试.plist是否存在
CbundleShortVersionString
键,最好像这样使用
PlistBuddy

/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" 1.plist || echo "CFBundleShortVersionString doesn't exist"

返回plist中包含文本“cbk”的所有行。由于某种原因,
plutil
将其输出发送到stderr。上面将stderr重定向到stdout,这样就可以将它成功地通过管道传输到
grep
(或者重定向到文件,或者任何您想要的内容)。

要回答您的问题,您可以创建一个小bash脚本,其中包含:

#!/bin/bash

cp $1 /tmp/$$.tmp
plutil -convert xml1 /tmp/$$.tmp
cat /tmp/$$.tmp
rm /tmp/$$.tmp
如果调用bash脚本pldump,请使用
chmod+x pldump
使其可执行。将其放置在路径中的某个位置,并像这样使用:

tlh-m0290:Preferences paul.downs$ ./pldump com.example.plist  
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict>
    <key>station.data.downloaded</key>
    <true/>
 </dict>
 </plist>
tlh-m0290:Preferences paul.downs$./pldump com.example.plist
station.data.com已下载

我看不到其他将plutil输出到stdout的方法。

plutil-extract CbundleShortVersionString xml1-o-App Info.plist
命令打印出CbundleShortVersionString
属性的内容

一行程序,它不依赖额外的实用程序来安装:


plutil-extract CbundleShortVersionString xml1-o-./Info.plist | sed-n“s/*\(.*\)./\1/p”

我想这一定是一个不同的版本,OP的问题中也有一个-show标志。我想我上面回答中的
2>&1
技巧会使
plutil
输出到
stdout
tlh-m0290:Preferences paul.downs$ ./pldump com.example.plist  
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict>
    <key>station.data.downloaded</key>
    <true/>
 </dict>
 </plist>