Data exchange between python script and bash script

Gregory Ewing greg.ewing at
Wed Apr 5 18:55:28 EDT 2017

Anssi Saari wrote:
> Bash manual explicitly states command substition (the $(...) structure)
> replaces the command with the standard *output* of the command.

Another problem is your use of '&' here:

    sensor_data=$(python &

The '&' causes the whole command, including the variable
assignment, to be executed in a subshell. So the variable
is only bound in the subshell process and won't be seen
from the main shell process.

Running the command in the background here is pointless,
since if the shell script needs the variable value for
subsequent processing it will have to wait for the
command to finish. So just get rid of the '&'.


More information about the Python-list mailing list