Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run shell script file on ipython at Google Colab

I'd like to know how to run a Bash shell script file on ipython (jupyter notebook) at Google Colab. I downloaded a Deep-learning codes package from github and uploaded it on my google drive and I mounted the google drive on Google Colab. The code package includes '*.py' python codes and 'fn.sh' script file. By executing the script file the python codes can be executed.

I tried os.system('fn.sh') and subprocess.call('fn.sh') on the ipython prompt at Google Colab but they doesn't work like below.

1)

import os
os.system('drive/DL/denet-master/examples/simple-cifar10.sh')
32256
import subprocess
subprocess.call('drive/DL/denet-master/examples/simple-cifar10.sh')
OSError: [Errno 8] Exec format error: 'drive/DL/denet-master/examples/simple-cifar10.sh'
like image 483
양유경 Avatar asked Sep 15 '18 09:09

양유경


People also ask

How do I run Ipython in Colab?

To run the code in any cell, you can click the run button on the left side of the code cell (looks like a “play” button with a triangle in a circle) or you can click [shift] + [enter]. The output will appear right below the code cell.

How do I run a command on Google Colab?

It's already possible to run terminal commands in a Colab notebook — all you need to do is prepend an exclamation to the command, or use the %%shell command, but sometimes you might prefer the convenience an interactive shell.


1 Answers

In Colab, you can invoke shell commands using either ! or %%shell.

Your invocation above would be:

!drive/DL/denet-master/examples/simple-cifar10.sh

Here's an example notebook:

https://colab.research.google.com/drive/1N7p0B-7QWEQ9TIWRgYLueW03uJgJLmka

like image 172
Bob Smith Avatar answered Sep 18 '22 18:09

Bob Smith