I am returning strings from a python module, for consumption within a bash script.
This is what I have so far:
SCRIPT_DIR=/somepath/to/scripts/folder
cd $SCRIPT_DIR/eod
python_cmd='import sys;
sys.path.append("/somepath/to/scripts/folder/utils");
import settings as st;
print " ".join(st.foo())'
# Fix indentation for Python
python_cmd=${python_cmd//' '/''}
my_array=(`python -c "$python_cmd"`)
I want to use the DRY philosophy in the snippet above. However, the string/somepath/to/scripts/folder is repeated in the script. I would like to pass the definition of $SCRIPT_DIR into the python_cmd - however I tried (replacing the path string in python_cmd with $SCRIPT_DIR/utils and it failed with the following error:
Traceback (most recent call last):
File "<string>", line 3, in <module>
ImportError: No module named settings
What am I doing wrong?
Note:
I am running bash 4.1.5