I’m trying to run a Python script from a shell script within a shell script, but I’m running into some problems.
Imagine my root shell script looks like this:
echo "test0" sh ./test/test1/test2.sh
and my test2.sh:
echo "test2" python testme.py
The python file is in the same directory as test2.sh
but test2.sh’s working directory seems to be the root’s so it cannot find the python script. So, if I give the python script’s absolute location to test2.sh
, the python file runs, but when the python file creates new files, it’s created in the root.
If there is a solution so that I don’t have to edit the python script to create new files in the directory of the python script, please let me know.
Advertisement
Answer
Here is your root script:
echo "test0" cd test/test1 sh ./test2.sh
Your script test2 is launched with the environment of your root script. So you just have to cd in your root script.