I want to run a script shell in colab, i used \"!\" and also i tried \"%%shell\"
Either %%shell
or !
should work. I suspect your shell script isn't in your current working directory.
You can check the contents of your current directory by running %ls
Here's a complete example of running a shell script: https://colab.research.google.com/drive/1i5lHPcsmcgeoFEGg0Dfwjhblsm2iMExP
If you're in a shell, you don't just call a .sh
file---you should get the same error in your own terminal. Your shell isn't looking in the current directory for shell commands, so you need to add some path context to your script to let shell know it's an actual runnable program, usually via adding a dot before your script, e.g., use
$ . testAllLatin.sh
instead of
$ testAllLatin.sh
Check What's the meaning of a dot before a command in shell? on the Unix Stack Exchange site. The top answer summarizes:
A dot in that context means to "source" the contents of that file into the current shell. With
source
itself being a shell builtin command. Andsource
and the dot operator being synonyms.
As far as Colab and Notebooks go, the %%shell
magic runs the entire cell as a command in a shell. So you should simply be able to use the following in a cell:
%%shell
. path/to/testAllLatin.sh
The bang instead runs just that single line in shell, so you can have Python interspersed if you want. So you could, in a cell, do something like this:
print('this is Python stuff', 5+10)
!. path/to/testAllLatin.sh
print('is it all latin?')
Probably best to keep the shell cells separate, anyways.