gpt4 book ai didi

shell - 如何在 shell 中逐行处理命令的输出?

转载 作者:行者123 更新时间:2023-12-03 11:35:26 25 4
gpt4 key购买 nike

我需要从 bash 脚本处理库的共享库依赖项。 for命令逐字处理:

for DEPENDENCY in `otool -L MyApplication | sed 1d`
do
...
done

逐行处理结果的方法是什么?

最佳答案

您应该使用 read命令。

otool -L MyApplication | sed 1d | \
while read i
do
echo "line: " $i
done

bashref有关 read 内置函数及其选项的说明。你也可以看看下面的 tutorial有关使用 read 的示例结合 for .

关于shell - 如何在 shell 中逐行处理命令的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3113005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com