Try Erlang escript.
In building out the Webmachine “clickstack” - I got into a slightly annoying mess with bash scripts. Bash isn’t really programming, more bashing the keyboard.
So escript to the rescue - escript is basically scripting erlang. Place:
At the top of the file - You can also invoke it via the little known “escript” command that ships with Erlang.
An actual example (which works) is here:
The main() function takes a list of “string” arguments - and what you do there is up to you.
I keep a tab open with http://erldocs.com in it - handy to find functions to do most things you would want to script.