Bruno Campos
Bruno Campos

Reputation: 666

How to write a script bash to enter multi-line input in jupyter-notebook?

I needed to write a script with configuration environment in only one cell. I want to leave it indented

!(python --version
 which python
 pip --version 
 conda --version 
 which conda) >> config-environment.txt

But cell not acept skip line between each command. How to write? Is it possible write bash script with indented in jupyter-notebook?

Upvotes: 24

Views: 16205

Answers (1)

Harshit Kumar
Harshit Kumar

Reputation: 12847

For your particular case, you can simply use semicolon at the end to run it i.e.

!(python --version; \
 which python; \
 pip --version; \
 conda --version; \
 which conda) >> config-environment.txt

For general case, you can use %%bash cell magic command to run the cell in bash i.e.

%%bash script magic

Run cells with bash in a subprocess.

%%bash

(python --version
 which python 
 pip --version 
 conda --version 
 which conda) >> config-environment.txt

You can also have a look at subprocess python module.

Upvotes: 39

Related Questions