1

I have a bash script that goes like this :

# 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

Now the problem is that when I try to execute the python script, it seens that the "working directory" is ., and not ./transfer_dir and I can't file the update_files copied earlier

How can I change that? I don't want to modify my python scripts too much since they are mostly location agnostic.

2 Answers 2

7

Use cd:

cd transfer_dir
# execute the python scripts 
python merge.py
# restore old directory
cd ..                         
Sign up to request clarification or add additional context in comments.

2 Comments

@Eric: It's good to be able to laugh at yourself; keeps you from getting too many ulcers.
As you might have noticed I am far from masterful in bash and I was expecting something extremely complicated for this task.
1
  1. you can change the path in the bash script @see ubuntus answer change working dir via bash

  2. you can change the working directory in the script itself

    import os

    os.chdir("transfer_dir")

I would recommend to use solution 1, just added 2. for completenes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.