在shell脚本中的shell脚本中从Python脚本创建文件

时间:2017-12-05 16:09:48

标签: python linux bash python-2.7 shell

我试图从shell脚本中的shell脚本运行Python脚本,但我遇到了一些问题。

想象一下,我的root shell脚本如下所示:

echo "test0"
sh ./test/test1/test2.sh

和我的test2.sh:

echo "test2"
python testme.py

python文件与test2.sh位于同一目录中,但test2.sh的工作目录似乎是根目录,因此无法找到python脚本。因此,如果我将python脚本的绝对位置赋予test2.sh,则python文件会运行,但是当python文件创建新文件时,它会在根目录中创建。

如果有解决方案以便我不必编辑python脚本以在python脚本的目录中创建新文件,请告诉我。

1 个答案:

答案 0 :(得分:1)

以下是您的根脚本:

echo "test0"
cd test/test1
sh ./test2.sh

您的脚本test2是使用根脚本环境启动的。所以你只需要在你的根脚本中使用cd。

相关问题