4
\$\begingroup\$

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.

ex:

#!/usr/bin/env bash

# save the string given in the sheband line
shebang_line="$1"

# remove it from $@
shift

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

test.py

#!/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?

\$\endgroup\$
2
\$\begingroup\$

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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