-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.

2
  • But basic Linux commands such as pwd and ls are running on it, without error. How come only shell is not running? Commented Apr 16, 2022 at 8: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. Commented Apr 16, 2022 at 9:48

1 Answer 1

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.

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

4 Comments

Throws error: OSError: [WinError 193] %1 is not a valid Win32 application
Are you running this on Windows?
yes. Windows> annoconda> spyder
You can't run bash scripts natively in Windows. You would needs something like Cygwin to make that possible. Once you have a valid bash runtime environment, refer stackoverflow.com/a/41645522/3730626 to get the bash script to run.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.