I'm attempting to write a bash script that should be able to collect data from ttyS0 and put in a variable.I need to talk with a device on the serial line, that is a module able to receive AT commands that I can send with echo > ttyS0 and capture the related answer in a variable. It's possible to do this without store the received answer in a variable  (i.e.cat /dev/ttyS0 & ), but if I try to put this data in a variable (i.e. VAR=$(cat /dev/ttyS0 &) it doesn't work (in VAR I can not find anything after the answer of the module). What I'm able to do by hand via gnome terminals (I'm working with a Ubuntu distribution) is the following:From a GNOME terminal that I call (A), I run (as root)# VAR=$(cat /dev/ttyS0) This command doesn't return the root prompt #, because probably cat /dev/ttyS0 is running and waiting for input.From another GNOME terminal that I call (B), I run# echo -en hello in VAR\r > /dev/ttyS0 The hello in VAR string should go to /dev/ttyS0 and put by cat in VARThen from (B):# killall catFrom GNOME terminal (A) I can see that the prompt (#) returns;Finally from GNOME terminal (A):# echo $VAR and I receive the hello in VAR string.I tried to implement this via bash script in this way:#!/bin/bashkillall catBASHTESTS_DIR=/root/Desktop/Tips_tricks_tutorials/bash_scriptingcd $BASHTESTS_DIRecho before VARcat_dev_ttyS0VAR=$(cat /dev/ttyS0)echo after VARcat_dev_ttyS0echo -en hello in VAR\r > /dev/ttyS0 sleep 2killall cat echo content of VAR: $VARexit 0but the script stops after echo before VARcat_dev_ttyS0How can I implement what I want or what I'm able to do with two GNOME terminals? 
attempting to put dynamic input data in a variable via cat method
shell;shell script;cat