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?

frazman
  • 32,081
  • 75
  • 184
  • 269

1 Answers1

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

pydvlpr
  • 311
  • 2
  • 6
  • Do you know why plain `python foo.py` doesn't work for him? – xvan Dec 10 '17 at 07:26
  • 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 – pydvlpr Dec 10 '17 at 07:56
  • Is that a python3 thing? At least python2 doesn't require ./ – xvan Dec 10 '17 at 08:27
  • 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. – pydvlpr Dec 10 '17 at 17:49