1

A script is executed from the shell as ./oximeter.

The script, oximeter, has 5 commands:

python3 ~/Documents/oximeter/3211ipod.py
ls -l
pwd
cd ~/Documents/oximeter/
pwd

The python script runs as expected. I would like the script to change the directory as shown in command #4. When control is returned to the user, the directory remains unchanged.

The second pwd returns the desired directory, however when control is returned to the user, pwd indicates that the directory is not ~/Documents/oximeter.

Why is this and is there a 'stronger' command that changes the target directory for the user?

This is in Ubuntu 20.04.

Eliah Kagan
  • 119,640
gatorback
  • 6,523

1 Answers1

0

because you only tell python3 to run the .py script from a directory and you would have to cd there first

(e.g. in the script :) cd $(dirname ~/myfolder/myscript.py) ;python3 myscript.py


you can get the location of your python script in python with:

print('abspath:     ', os.path.abspath(__file__))
print('abs dirname: ', os.path.dirname(os.path.abspath(__file__)))

https://www.tutorialspoint.com/python3/os_getcwd.htm