How to run a shell script in Jupyter Notebook?

10,195

Solution 1

You can also simply run any script by typing in a jupyter notebook cell:

%%sh
cat myscript.sh 
./myscript.sh

Solution 2

chmod +x Heasoft.sh should fix this. If not, add #!/bin/bash at top of the shell script.

Share:
10,195
becky.rrr
Author by

becky.rrr

Updated on June 04, 2022

Comments

  • becky.rrr
    becky.rrr over 1 year

    So I have this shell script that runs a program that I'll be using in Jupyter, but is bash-oriented, and I tried using the subprocess module,and I get the error: OSError: [Errno 13] Permission denied. However, the script is in my directory with the ipynb file, so I should have permission.

    import subprocess
    subprocess.call(['./Heasoft.sh'])
    

    That's literally all I have; it works in the terminal but not in the Notebook. Is there something I'm doing wrong?

    • Sha
      Sha almost 4 years
      try like subprocess.call('./Heasoft.sh', shell=True)
    • becky.rrr
      becky.rrr almost 4 years
      I did that, and it ran! But I got an output of a number, is that normal?
    • Sha
      Sha almost 4 years
      it's better you put expected output from the script and put some code to reproduce the error. then it's easy anyone to help you out. Also do your script file have enough permissions? do chmod u+x Heasoft.sh