Hi,
{
read -N 4 var
n=${var%%:*}
read -N "$((n-${#n}))" rest
json=${var#*:}$rest
} < /dev/tcp/127.0.0.1/2828
echo "$json"
# echo will print '{"applicationType":"gecko","marionetteProtocol":3}'
I use the above code to get information from firefox marionette server
(it can be started with firefox --marionette command line option).
The above bash code has to be put in { } so that the connection to
/dev/tcp/127.0.0.1/2828 will not be reset.
For debugging purposes, I want to ensure the connection is not closed,
once I run a bash command even without {} (as interactive commands can
not be run in { }).
If I just run the following command in an interactive session,
read -N 4 var < /dev/tcp/127.0.0.1/2828
the next time when I run the following command, it will basically
establish a new connection to /dev/tcp/127.0.0.1/2828.
read -N "$((n-${#n}))" rest < /dev/tcp/127.0.0.1/2828
This is not what I want.
How can I solve this problem so that the connection to this tcp port
is not reset every time when I run an interactive bash command?
--
Regards,
Peng