简体   繁体   English

bash for循环不按预期工作

[英]bash for loop not working as expected

I have six openvswitches that I have created using mininet.I want to dump the flow tables using a very simple bash script.For some reason this doesn't seem to be working. 我有六个openvswitch,我使用mininet创建。我想使用一个非常简单的bash脚本转储流表。由于某种原因,这似乎不起作用。

for i in `sudo ovs-vsctl list-br` ; do {`sudo ovs-ofctl dump-flows $i`}  ; done

gives the output 给出输出

{NXST_FLOW: command not found
{NXST_FLOW: command not found
{NXST_FLOW: command not found
{NXST_FLOW: command not found
{NXST_FLOW: command not found
{NXST_FLOW: command not found

However if I do 但是,如果我这样做

for i in `sudo ovs-vsctl list-br` ; do echo $i  ; done

I get the below output. 我得到以下输出。

s1 s2 s3 s4 s5 s6 s1 s2 s3 s4 s5 s6

By the way I am able to do 顺便说一句我能做到的

sudo ovs-ofctl dump-flows s1

and get the right information. 并获得正确的信息。

What is wrong with my bash script.? 我的bash脚本有什么问题。

Why use the backticks? 为什么要使用反引号? Just do 做就是了

for i in `sudo ovs-vsctl list-br` ; do sudo ovs-ofctl dump-flows $i ; done

try: 尝试:

for i in sudo ovs-vsctl list-br ; 我在sudo ovs-vsctl list-br ; do sudo ovs-ofctl dump-flows $i; 做sudo ovs-ofctl dump-flows $ i; done DONE

You're using command substitution and command grouping all at once. 您正在使用命令替换命令分组

You told bash to run the command (the backticks) and then treat the output as another command to run. 你告诉bash运行命令(反引号),然后将输出视为另一个运行命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM