我正在尝试以下脚本
#!/bin/bash
OUTPUT="$(cat /Users/admin/Desktop/plist-script-output/keys-updated.txt | sed 's/"//g; s/^/-c "Print :/g; s/$/"/g' | tr '\n' ' ')"
FILE="/Users/admin/Desktop/plist-script-output/plist-data/data.plist"
PLISTBUDDY=$(/usr/libexec/PlistBuddy $OUTPUT $FILE 2>&1)
echo "$PLISTBUDDY"以上脚本的输出是不可识别的命令
输出变量的值为
-c打印:Ant-转换“-c”打印:Newitem“-c”打印:区域“-c”打印:联系人
添加2>&1,以便同时打印错误(不存在键)和正确的输出。
keys-updated.txt包含要从plist文件中提取的密钥列表(不一定所有都在plist中)。
解决办法(不起作用)
尝试了“Nahuel”的解决方案。不过,这行
-$PLISTBUDDY=$;/usr/libexec/PlistBuddy "$@“"$FILE")
仅提供不存在于plist中的键的列表。
这是我在使用@Nahuel的解决方案后收到的输出
打印:条目“状态”不存在
打印:条目“通知”不存在
打印:条目"IsMvnMgrSupported“不存在
打印:条目"BuildsetFile“不存在
打印:条目"RollupClocReportToModule“不存在
打印:条目“分支”不存在
打印:条目“Ant-转换”,不存在。
打印:条目"IndexTag“不存在
打印:条目"WO“不存在
打印:条目“标签”不存在
印刷品:条目"Newitem“不存在
如何直接在命令行上使用该命令
管理:桌面管理$。/usr/libexec/PlistBuddy -c "Print :Area“-c "Print :Contact”-c "Print :Email“-c "Print :Language”-c "Print :Location“-c”-c "Print :Name“-c "Print :Notes”-c "Print :宗旨“-c "Print :Track”-c "Print :Type“-c "Print :URL”-c "Print :Status“-c "Print :Notify”-c "Print :IsMvnMgrSupported打印:BuildsetFile“-c”打印:RollupClocReportToModule“-c”打印:分支“-c”打印:Ant-转换“-c”打印:IndexTag“-c”打印:WO“-c”打印:标签“-c”打印:Newitem“-c”打印
结果是
监测葫芦。是的。爪哇。dvfvfvfvfvfvfv .ActiveMQ。是的。来自.的消息传递(JMS)框架
基础设施。框架。jdbcjdbcdjdcnnjn .打印:条目,":Status",不存在。打印:条目“:通知”,不存在。打印:条目":IsMvnMgrSupported",不存在。打印:条目":BuildsetFile",不存在。打印:条目":RollupClocReportToModule",不存在。打印:条目“:分支”,不存在。打印:条目“:蚂蚁转换”,不存在。打印:条目":IndexTag",不存在。打印:条目":WO",不存在。打印:条目“:标签”,不存在。打印:条目":Newitem",不存在。中止陷阱: 6
发布于 2017-06-14 09:02:22
在查看sed和tr命令之后。似乎/Users/admin/Desktop/plist-script-output/keys-updated.txt包含
Ant-Conversion
Newitem
Area
Contact整个过程可以通过bash内置完成:
# local args arr pcmd (if inside a function)
# readarray -t arr </Users/admin/Desktop/plist-script-output/keys-updated.txt
# because readarray doesn't work on Mac
IFS=$'\n' read -d '' arr </Users/admin/Desktop/plist-script-output/keys-updated.txt
args=()
for pcmd in "${arr[@]}"; do
args+=(-c "Print :$pcmd")
done
PLISTBUDDY=$(/usr/libexec/PlistBuddy "${args[@]}" "$FILE" 2>&1)第一个答案:
OUTPUT='-c "Print :Ant-Conversion" -c "Print :Newitem" -c "Print :Area" -c "Print :Contact"'引号不是语法,因为报价处理是在变量展开之前完成的。
不安全(注射),在这种情况下使用eval
PLISTBUDDY=$(eval /usr/libexec/PlistBuddy $OUTPUT $FILE 2>&1)暂时想不出更好的事情
稍微好一点
PLISTBUDDY=$(eval set -- $OUTPUT;/usr/libexec/PlistBuddy "$@" "$FILE" 2>&1)https://stackoverflow.com/questions/44539127
复制相似问题