0

I am using a Linux terminal app, it works flawlessly but I think I am having a problem here, and I don't know if it's an app or a me-error

below is my test.sh, everything in #comment is what i get after each line is called/runs, but note that this would normally be 2 files i guess, just brought them together

#!/bin/bash

echo "this is a test"
 # this is a test
ls
 # code downloads
pwd
 # /data/data/com.termux/files/home
ls code
 # python
ls code/python
 # scripts programs
ls code/python/scripts
 # abc.py test.py
cd code/python/scripts
pwd
 #/data/data/com.termux/files/home/code/python/scrips
ls
 # abc.py test.py
python3 test.py
 # hello world
cd
python3 code/python/scrips/abc.py
 # python3: can't open file '/data/data/com.termux/files/home/code/python/scrips/abc.py': [Errno 2] No such file or directory
python3 code/python/scrips/test.py
 # python3: can't open file '/data/data/com.termux/files/home/code/python/scrips/test.py': [Errno 2] No such file or directory

important to note is that if i run python3 code/python/scrips/abc.py in home, it works though. this is all i could do with testing and trying stuff out myself, all you see above is me "debugging"

I've seen shell programming questions here before, so I think it's an ok question.

7
  • The cd command, without any arguments, changes the current directory to your home directory. Commented Jan 25, 2021 at 17:31
  • Try pwd and echo $HOME after that last cd. They should be the same. Commented Jan 25, 2021 at 17:34
  • Remove that last cd (the one that is alone in its line) and your script will run fine. Commented Jan 25, 2021 at 17:34
  • 1
    @accdias - no, python3 code/python/scrips/abc.py won't work without moving back to the original directory. Its more likely that /data/data/com.termux/files/home isn't the home directory. Commented Jan 25, 2021 at 17:36
  • in the bash script include on a single line env | grep PATH and see whether the path where python3 exists is included. Are you actually running this script interactively or are you running it from something like cron? If you don't run it interactively you loose all path information and have to define the path inside the bash script. Commented Jan 25, 2021 at 17:46

1 Answer 1

1

This is a path problem. After you run cd just before running the two python3commands you need to check the path that you return to.

If you were in a subdirectory e.g: sub1

you would then have travelled to sub1/code/python/scripts

but running cd sends you back to $HOME or /home/username.

This means that running python3 with the arguments code/python/scripts/abc.py will always fail because you are not in the correct starting folder.

So the issue is the line cd. This is causing all the problems.

cd && python3 code/python/scrips/abc.py

The cd command is only applied in the context of that signal line. On the next line you will be back in the current working directory.

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

1 Comment

not quite, as you see, i start in the home directory, i go to scripts, i run the script, i go back to home, i run the same path again i just cd'd to before where i proved that it existed, Nd it doesn't work.

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.