bash 从 plutil 获取信息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8778368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:15:39  来源:igfitidea点击:

getting info from plutil

iosbashshell

提问by lewis denny

I'm having trouble direction info from plutil. I want to check if a .plist contains the key CFBundleShortVersionString. I don't think plutil has any option to test for if a key exists so I thought I would just plutil -show file.plist >file.txtbut that just plain doesn't work. :/ So I tried to direct the plist file from stdout to file with the dump option plutil -dump file.plist >file.txtwith no luck. :/ I also tried directing the stdout to stderr and stderr and stdout to file. Nothing worked. How do I do this?

我在从 plutil 获取方向信息时遇到问题。我想检查 .plist 是否包含密钥 CFBundleShortVersionString。我认为 plutil 没有任何选项可以测试密钥是否存在,所以我认为我会这样做,plutil -show file.plist >file.txt但这只是简单的行不通。:/ 所以我试图将 plist 文件从标准输出定向到带有转储选项的文件,但plutil -dump file.plist >file.txt没有运气。:/ 我也尝试将标准输出定向到标准错误和标准输出以及标准输出到文件。没有任何效果。我该怎么做呢?

回答by Zsolt Szatmari

Oneliner which doesn't depend on extra utility to install:

Oneliner 不依赖于额外的实用程序来安装:

plutil -extract CFBundleShortVersionString xml1 -o - ./Info.plist | sed -n "s/.*<string>\(.*\)<\/string>.*/\1/p"

plutil -extract CFBundleShortVersionString xml1 -o - ./Info.plist | sed -n "s/.*<string>\(.*\)<\/string>.*/\1/p"

回答by Andrey Starodubtsev

If you need to test your .plist for the existence of the CFBundleShortVersionStringkey, it's better to use PlistBuddylike this:

如果您需要测试您的 .plist 是否存在CFBundleShortVersionString密钥,最好这样使用PlistBuddy

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

回答by BoygeniusDexter

plutil -extract CFBundleShortVersionString xml1 -o - App-Info.plistcommand prints out the content of CFBundleShortVersionStringproperty

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

回答by MikeBeaton

$ plutil -show StorePurchasesInfo.plist 2>&1 | grep cbk

returns all lines in the plist with the text 'cbk' in them. For some reason plutilsends its output to stderr. The above redirects stderr to stdout, so it can then be successfully piped on to grep(or redirected to a file, or whatever you want).

返回 plist 中包含文本 'cbk' 的所有行。出于某种原因,plutil将其输出发送到 stderr。上面将 stderr 重定向到 stdout,因此可以成功地将其传送到grep(或重定向到文件,或任何您想要的)。

回答by Diziet

To kind of answer your question, you could create a little bash script containing:

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

#!/bin/bash

cp  /tmp/$$.tmp
plutil -convert xml1 /tmp/$$.tmp
cat /tmp/$$.tmp
rm /tmp/$$.tmp

If you call the bash script pldump make it executable with chmod +x pldump. Place it somewhere in your path and use it like so:

如果您调用 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>

I can see no other way of making plutil output to stdout.

我看不出有其他方法可以将 plutil 输出到标准输出。