Question

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?

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top