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...