input of while loop to come from output of `command`

后端 未结 4 1698
心在旅途
心在旅途 2021-02-04 02:16
#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=$(         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 02:45

    This is sh-compatible:

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

    However, sh does not have arrays, so you can't have your code like it is in sh. Others are correct in saying both bash and perl are nowadays rather widespread, and you can mostly count on their being available on non-ancient systems.

    UPDATE to reflect @Dennis's comment

提交回复
热议问题