Thursday, 18 May 2017

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




#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



The following fails to work.



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



Too few results on Google (doesn't understand what I want to find :( ). I'd like to keep it Bourne-compatible (/bin/sh), but it doesn't have to be.


Answer



for line in $(tcpdump -n -r $pcap)  
do
command
done


This isn't exactly doing what I need. But it is close. And Shell compatible. I'm creating HTML tables from the tcpdump output. The for loop makes a new row for each word. It should make a new row for each line (\n ending).

Paste bin script01.sh.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...