从bash调用python,如何更改python工作目录?
我有一个bash脚本,如下所示:从bash调用python,如何更改python工作目录?,python,bash,working-directory,Python,Bash,Working Directory,我有一个bash脚本,如下所示: # gets all relevant files in the directory cp ../update_files/* ./transfer_dir # copy the python scripts to that directory cp ../tools/update_tool/* ./transfer_dir # execute the python scripts python ./transfer_dir/merge.py 现在的问题
# gets all relevant files in the directory
cp ../update_files/* ./transfer_dir
# copy the python scripts to that directory
cp ../tools/update_tool/* ./transfer_dir
# execute the python scripts
python ./transfer_dir/merge.py
现在的问题是,当我尝试执行python脚本时,它发现“工作目录”是.,而不是./transfer\u dir,并且我无法对先前复制的更新\u文件进行归档
我怎样才能改变这一点?我不想对python脚本进行太多修改,因为它们大多不知道位置。使用cd
:
cd transfer_dir
# execute the python scripts
python merge.py
# restore old directory
cd ..
使用cd
:
cd transfer_dir
# execute the python scripts
python merge.py
# restore old directory
cd ..
我建议使用解决方案1,只添加了2。对于完美主义者。@Eric:能够嘲笑自己是件好事;防止你患太多溃疡。正如你可能已经注意到的那样,我在bash方面还远远不够精通,我希望这项任务能有一些非常复杂的东西。@Eric:能够自嘲真好;防止你患上太多溃疡。你可能已经注意到,我对bash的掌握还远远不够,我期待着这个任务会有非常复杂的事情发生。