Search code examples
pythonbashshellvariablespiping

How can I get the variable that a python file with a path prints when I call that python file from a shell script?


For some reason when I run this in my shell script only $exec_file and $_dir get passed into module_test.py, but neither $filename nor $modified_file get passed.

mod_test=$( /path/module_test.py $modified_file $_dir $filename )

(path is just a normal path that I decided to shorten for the sake of this example) Am I typing this wrong? I am trying to get the output (an integer) of my module_test.py to be put into the variable mod_test.

My variables are:

modified_file = _File
_dir = /path to directory/
file = _File.py

Solution

  • Based on your example, you need to surround $_dir with quotes because it contains spaces, i.e.:

    mod_test=$( /path/module_test.py $modified_file '$_dir' $filename )