ios - 通过shell脚本plist buddy从plist读取数组

标签 ios shell plist

我已经编写了从 plist 中读取数组的 shell 脚本。

PLIST_PATH="./../Documentation/documentation.plist"
echo "PATH = $PLIST_PATH"
FILE_ARRAY=`/usr/libexec/PlistBuddy -c "print :'public-headers'" $PLIST_PATH`

现在我想从这个数组中检索所有字符串,但我无法从这个数组中获取计数。

请帮忙。

最佳答案

安全的方法是使用索引的单独 Print 语句遍历数组,直到再也找不到键为止。 下面的脚本打印给定数组键和 plist 中的条目数

PLISTBUDDY="/usr/libexec/PlistBuddy -c"
if [ "$#" -ne 2 ]; then
  echo "usage: $0 <array key> <plistfile>"
  exit 1
fi
KEY=$1
PLIST=$2
i=0
while true ; do
   $PLISTBUDDY "Print :$KEY:$i" "$PLIST" >/dev/null 2>/dev/null
   if [ $? -ne 0 ]; then
      echo $i
      break
   fi
   i=$(($i + 1))
done

关于ios - 通过shell脚本plist buddy从plist读取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23518370/

相关文章:

java - 在 Windows 上使用 Cygwin 排序时出现 "Input file specified two times."错误

ios - 自动更新 plist CFBundleShortVersionString 和 CFBundleVersion

ios - 如何比较前缀 header 中的 $PRODUCT_NAME?

ios - 我可以将敏感信息放入 iOS 应用程序的源代码中吗?

ios - UITableViewCell内存中的异步图像加载问题

shell - 仅在构建失败时执行最终脚本

bash - 列出包含 `n` 或更少行的文件

项目重命名后 iPhone 应用程序图标显示为空白

ios - 无法在 plist 文件 xcode 5 中添加行

ios - 试图让 iOS 13 项目与 iOS 12 兼容