Reputation: 11
I am executing following command successfully from linux env,
[UdayaShankar Das@lxapp-3]# tshark -r sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*\s\(\(\s[0-9a-f][0-9a-f]\)\{1,16\}\).*$/\1/p'
ff ff ff ff ff ff 00 10 94 00 00 0a 08 06 00 01 08 00 06 04 00 01 00 10 94 00 00 0a c0 01 01 02 00 00 00 00 00 00 c0 01 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bu the above command failing when trying from tcl shell through exec command and back tik operator . Please advise.
% [ exec tshark -r /home/arts2/STC_CAPTURE/sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*s((s[0-9a-f][0-9a-f]){1,16}).*^A/p' ]
invalid command name "0-9a-f"
UPDATE:
thanks for your suggestion. I tried but seems not working :(
% set cmd34 {tshark -r /home/arts2/STC_CAPTURE/sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*s((s[0-9a-f][0-9a-f]){1,16}).*^A/p'}
tshark -r /home/arts2/STC_CAPTURE/sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*s((s[0-9a-f][0-9a-f]){1,16}).*^A/p'
% [ eval exec $cmd34]
invalid command name "0-9a-f"
Also tried with second option
%set cmd34 {tshark -r /home/arts2/STC_CAPTURE/sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*s((s[0-9a-f][0-9a-f]){1,16}).*^A/p'}
tshark -r /home/arts2/STC_CAPTURE/sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*s((s[0-9a-f][0-9a-f]){1,16}).*^A/p'
% [ exec {*}$cmd34 ]
extra characters after close-brace
Upvotes: 0
Views: 1148
Reputation: 137567
When you have a chunk of shell script like this:
tshark -r /home/arts2/STC_CAPTURE/sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*s((s[0-9a-f][0-9a-f]){1,16}).*^A/p'
The simplest method of running it is to use:
set shellscript {tshark -r /home/arts2/STC_CAPTURE/sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*s((s[0-9a-f][0-9a-f]){1,16}).*^A/p'}
set response [exec /bin/sh -c $shellscript]
Alternatively, change the single quote characters to braces:
exec tshark -r /home/arts2/STC_CAPTURE/sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n {s/^[0-9a-f]*s((s[0-9a-f][0-9a-f]){1,16}).*^A/p}
Upvotes: 2
Reputation: 16428
You can set the command into a variable and use {*}
or eval
to evaluate it.
set cmd {tshark -r sim_venom_sanity_DEVICE1_PORT1_1_capture.pcap -Vx -R frame.number==2 | sed -n 's/^[0-9a-f]*\s\(\(\s[0-9a-f][0-9a-f]\)\{1,16\}\).*$/\1/p'}
puts [ eval exec $cmd ]
If you have a tcl 8.5 or higher , you can use the below code, instead of eval
puts [ exec {*}$cmd ] ; # {*} is for argument expansion which is recommended
Please note that the expression is enclosed with braces to avoid any substitutions and treat them as literal values. If you need to use braces in the expression, make sure you are escaping it with backslash like \{
Upvotes: 1