'Windows: Unable to run a shell script in spyder (python 3.8). Invalid Syntax error [duplicate]

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.



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M B