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?
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]
精彩评论