It is commonly known that env does not allow passing of arguments - at least not reliably. There are various workarounds described here, but they felt to hacky and unreadable to me. That's why I developed an alternative, ex.


#!/usr/bin/env bash

# save the string given in the sheband line

# remove it from $@

# execute 
# not quoting shebang_line is intentional
eval $(echo $shebang_line "$@")


#!/usr/local/bin/ex python "-i"
# quoting the arguments is possible
import sys

print('hello', sys.argv)

It works surprisingly well, but I don't like the eval-echo thing. I tried experimenting with arrays, but haven't found a solution. Any tips?


1 Answer 1


I don't recommend calling your program ex. That name has a well established meaning in the Unix world as the name of a text-editing tool.

  • \$\begingroup\$ I have never heard of this before, thank you for pointing that out. \$\endgroup\$
    – corvus_192
    Commented Sep 8, 2017 at 7:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.