-1

I am trying to run a shell script in Spyder (Python 3.8). I have tried the following and all this is giving me the same error - Invalid Syntax

  1. bash ./filename.sh

  2. bash filename.sh

  3. sh filename.sh

  4. sh ./filename.sh

  5. shell ./filename.sh

  6. shell filename.sh

  7. import subprocess subprocess.run(.\filename.sh)

  8. source filename.sh

enter image description here

9.

import subprocess
subprocess.run(filename.sh)

The last one gives the error:

name 'filename' doesn't exist.

Note: I have rechecked my pwd.

  • But basic Linux commands such as pwd and ls are running on it, without error. How come only shell is not running? – Sachin Motwani Apr 16 '22 at 08:45
  • I don't think your question contains enough details to troubleshoot this. Please [edit] to reveal your OS, how and where Bash and/or `sh` are installed, etc. – tripleee Apr 16 '22 at 09:48

1 Answers1

0

Add quotes

subprocess.run("filename.sh")

Also, I would like to point out that unless you are using some package to add the syntax bash, sh, etc... you would get the syntax error since Python doesn't know what those keywords mean.

M B
  • 739
  • 8
  • 13