bashスクリプト内で使用するために、Pythonモジュールから文字列を返しています。
これは私がこれまでに持っているものです:
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"`)
上記のスニペットでDRY哲学を使用したいと思います。ただし、文字列/somepath/to/scripts/folder
はスクリプト内で繰り返されます。$ SCRIPT_DIRの定義をpython_cmdに渡したいのですが、試しました(python_cmdのパス文字列を$ SCRIPT_DIR / utilsに置き換えたところ、次のエラーで失敗しました:
Traceback (most recent call last):
File "<string>", line 3, in <module>
ImportError: No module named settings
私は何が間違っているのですか?
ノート:
私はbash4.1.5を実行しています