Scripting Alternative to Bash

I really don’t like to write bash script. I prefer use python as my shell language, but I have to admit that in some cases, bash script can be simpler than python.

I found the discussion Are there any languages that compile to Bash?

someone mention Plumbum for python and ShellJS for nodejs both reimplement some unix tools. I tried both, here’s what I learned.

  • Plumbum: overriding many python operator | < > …etc. give these operator new meaning such that > or < for redirect.

  • ShellJS: javascript syntax not as simple as python, but there are coffee script/livescript which provide much elegant syntax, make this library worth using.

there is a third option: ipython, after I read the book

Python for Unix and Linux System Administration

ipython is really amazing, I use it as my default pytohn REPL, this book give me lot’s of way to write a bash like script in python way, oh… not exactly pure python, ipython invent some of it’s own syntax.

here are some example

  • !ls: execute ls
  • !ls | grep config: ls with filter
  • %rehash: hash command in PATH. make unix command can be use inside ipython REPL.
(ipython) user = 'root'
(ipython) process = 'bash'
(ipython) listofitem = !ps aux | grep $user | grep $process

script can be store in *.ipy for future use.