1

I was hoping it would be easy to rewrite a few bash scripts using ipython by using the "!" command. Unfortunately if I try to run ipython in non-interactive mode like so:

ipython -p sh myipythonscript.py

where myipythonscript.py contains commands like:

env=%env
d=!ls

This doesn't work. I get SyntaxError. Is there an option which allows ipython to be run in non-interactive mode?

pontikos
  • 1,433
  • 2
  • 11
  • 7

1 Answers1

0

Python also has modules which makes it easy to completely replace bash calls. these are easier to debug and give better error handling.

for example instead of ls you can use glob, it supports the same syntax:

files=glob.glob('myfiles*.txt')

for environment variables:

env = os.environ

for path related functions:

os.path

for common operations, os.mkdir, os.chmod, os.getcwd [same as pwd]

Andrea Zonca
  • 8,378
  • 9
  • 42
  • 70