1

I am trying to write a simple bash file able to capture Wi-Fi traffic that looks like this:

STRING1="tshark -i 2 -a duration:5 -w <path of output.pcap>"
$STRING1
echo "'Wi-Fi' captured"

STRING2="tshark -r <path of output.pcap> -T fields -e frame.number -E header=y > <path of output.csv>"
echo $STRING2
$STRING2

The first command STRING1 is correctly processed and output.pcap is created. When STRING2 is launched i get the error tshark: Syntax error.. But if I just copy and paste the STRING2 command in the terminal everything works fine. What am I missing here?

1
  • Is it possible that your paths have spaces in them? Commented Mar 4, 2013 at 11:21

1 Answer 1

1

Shell syntax (redirection operators, pipes, etc) are parsed before word expansion, so your output redirection is being passed as arguments to tshark.

STRING2="tshark -r <path of output.pcap> -T fields -e frame.number -E header=y"
echo $STRING2
$STRING2 > <path of output.csv>
Sign up to request clarification or add additional context in comments.

1 Comment

Definitely a new-by in bash, am I? Thank you chepner!

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.