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

Sachin
  • 239
  • 3
  • 13
  • But basic Linux commands such as pwd and ls are running on it, without error. How come only shell is not running? – Sachin 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
  • 2,700
  • 2
  • 15
  • 20
  • Throws error: OSError: [WinError 193] %1 is not a valid Win32 application – Sachin Apr 16 '22 at 07:16
  • Are you running this on Windows? – M B Apr 16 '22 at 07:18
  • yes. Windows> annoconda> spyder – Sachin Apr 16 '22 at 07:18
  • 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 https://stackoverflow.com/a/41645522/3730626 to get the bash script to run. – M B Apr 16 '22 at 07:22