0

Could you please advise , I'm trying to run a "for" loop on a shell command line

for i in `seq 4`; do `wireshark &`; done

From some reason the loop isn't finish and only 1 wireshark window is open

Could you please advise? enter image description here

3
  • 3
    Since you'll likely get comments or even answers on that, your loop would be prettier to the modern shell scripter if it was written as for ((i=0; i<4; i++)); do wireshark &; done. That most likely won't fix your problem though Commented Nov 5, 2020 at 15:25
  • Why on earth did you put wireshark & in backticks? Commented Nov 5, 2020 at 15:29
  • Wireshark needs a GUI and so you won't be able to run it to the background. Commented Nov 5, 2020 at 15:30

3 Answers 3

3

You really don't want to put wireshark & in backticks. The shell that executes your loop creates a subshell to run wireshark and is waiting for that subshell to close all of its open file descriptors that are writing to stdout so that it can collect the data written. (That's what the bacticks do!). If you just want to run wireshark in the background, then this should work:

for ...; do wireshark & done

Note that backticks is pretty ancient syntax, and $() has been preferred since the mid 90s at least. If you're going to use seq you should write it as for i in $(seq 4); do .... You're using bash, so you could do for((i=0; i <4; i++)). There are a lot of ways to do the iteration, but that's not relevant to the issue you're having.

Sign up to request clarification or add additional context in comments.

Comments

0

You don't need to use seq external command in bash and `wireshark &` is not correct - backticks are used for command substitution but notice that $() is recommended over backticks these days. It should be:

for i in {1..4}; do wireshark & done

Comments

-2

You may try this

for VARIABLE in file1
do
    command1 on $VARIABLE
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.