0

I am noob in bash script and I am trying to do the following..

I have a directory structure like

root/
root/execute.sh
root/python/foo.py

I want to execute foo.py I did something like following in execute.sh

#!/bin/sh
cd python
python foo.py

But it throws an error that foo.py is not there. How do i fix this?

4
  • stackoverflow.com/questions/6659689/… Commented Dec 10, 2017 at 7:11
  • how are you running execute.sh? Commented Dec 10, 2017 at 7:14
  • @xvan ./execute.sh Commented Dec 10, 2017 at 7:18
  • 1
    I couldn't reproduce, try adding pwd and ls to the shell script, after cd python to make sure that foo.py is there. Commented Dec 10, 2017 at 7:23

1 Answer 1

2

In your script you should try

python ./foo.py 

Or you add the directory /root/python to root's PATH-variable. You can do this in the users .bashrc file by adding

PATH=$PATH:/root/python
export PATH

Hope that helps.

Best,

me

Sign up to request clarification or add additional context in comments.

4 Comments

Do you know why plain python foo.py doesn't work for him?
If you want to run a script within the current directory you need to use ./ , otherwise the system trys to find it in the users PATHs
Is that a python3 thing? At least python2 doesn't require ./
I made a mistake in my explanation. my explanation generally refers to the execution of executables on *nix systems. I had the time to test the given scenario, now. With my systems (archlinux and debian) I did not get any errors. I have tested with python 2 and 3.

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.