gpt4 book ai didi

shell - while 循环的输入来自 `command` 的输出

转载 作者:行者123 更新时间:2023-12-03 12:29:17 24 4
gpt4 key购买 nike

#I used to have this, but I don't want to write to the disk
#
pcap="somefile.pcap"
tcpdump -n -r $pcap > all.txt
while read line; do
ARRAY[$c]="$line"
c=$((c+1))
done < all.txt

以下无法工作。
# I would prefer something like...
#
pcap="somefile.pcap"
while read line; do
ARRAY[$c]="$line"
c=$((c+1))
done < $( tcpdump -n -r "$pcap" )

Google 上的结果太少(不明白我想找到什么 :( )。我想保持它与 Bourne 兼容 (/bin/sh),但不是必须的。

最佳答案

这是sh -兼容的:

tcpdump -n -r "$pcap" | while read line; do  
# something
done

然而, sh没有数组,所以你不能像 sh 那样拥有你的代码.其他人说的都是正确的 bashperl现在相当普遍,并且您大多可以指望它们在非古代系统上可用。

更新 反射(reflect)@Dennis 的评论

关于shell - while 循环的输入来自 `command` 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2983213/

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