English 中文(简体)
B. “共同产出”产生的时段投入 ......
原标题: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  

以下因素未能奏效。

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

谷歌成果太少(没有了解我想要找到的东西): 我愿保留“Bourne-compatible”(/bin/sh),但现在只有 持<>。

最佳回答

(sh-compatible:

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

但是,<代码>sh没有阵列,因此您的代码与sh一样。 其他发言者说,<条码>bash和perl目前相当普遍,而且你可以主要依靠非重要系统提供。

<>UPDATE,以反映@Dennis s comment

问题回答

这部建筑在篮子里:

while read line; do  
  ARRAY[$c]="$line"
  c=$((c+1))  
done < <(tcpdump -n -r "$pcap")

如果你不关心 being,你可以转往伯尔:

my $pcap="somefile.pcap";
my $counter = 0;
open(TCPDUMP,"tcpdump -n -r $pcap|") || die "Can not open pipe: $!
";
while (<TCPDUMP>) {
    # At this point, $_ points to next line of output
    chomp; # Eat newline at the end
    $array[$counter++] = $_;
}

或按批号使用,

for line in $(tcpdump -n -r $pcap)  
do  
 command  
done  
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 <tr> row for each word. It should make a new row for each line ( ending). Paste bin script01.sh.





相关问题
KornShell- Creating a fixed width text file

I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...

unix find command

how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......