|
|
|
|
|
by Klasiaster
4151 days ago
|
|
For me combing the best parts of bash and ipython is the way to go. Up to now this seems more comfortable to me than using subprocess in python or this haskell aproach which needs to be aware of every programme output to give what it promises. You can easily copy big parts of existing bash scripts and e.g. add error handling in the python way :) Even I think for loops/list comprehensions are betten than the strange bash syntax. And here a short example:: #!/usr/bin/env ipython3
#
# 1. echo "#!/usr/bin/env ipython3" > scriptname.ipy # creates new ipy-file
#
# 2. chmod +x scriptname.ipy # make it executable
#
# 3. starting with line 2, write normal python or do some of
# the ! magic of ipython, so that you can use shell commands
# within python and even assign their output to a variable via
# var = !cmd1 | cmd2 | cmd3 # enjoy ;)
#
# 4. run via ./scriptname.ipy - if it fails with recognizing % and !
# but parses raw python fine, please check again for the .ipy suffix which must be there!
#
# ugly example, please go and find more in the wild
files = !ls *.* | grep "y"
for file in files:
!echo $file | grep "p"
# sorry for this nonsense example ;)
# it's even possible to access the output of a command by outputvariable.s, .p or .n
# see file:///usr/share/doc/ipython-doc/html/interactive/reference.html#system-shell-access
Better take a look here, it's more complete:
https://blog.safaribooksonline.com/2014/02/12/using-shell-co... |
|
0: http://gibiansky.github.io/IHaskell/ 1: https://registry.hub.docker.com/u/gregweber/ihaskell/