liv2hak
liv2hak

Reputation: 14970

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.

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

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.?

Upvotes: 1

Views: 270

Answers (3)

Andy Jones
Andy Jones

Reputation: 6275

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.

Upvotes: 0

nicky_zs
nicky_zs

Reputation: 3773

try:

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

Upvotes: 0

nneonneo
nneonneo

Reputation: 179402

Why use the backticks? Just do

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

Upvotes: 4

Related Questions