pretty cool. instead of putting the eval() inside the script a shebang also works.<p>#!/usr/bin/env -S bash -c 'argc -e ${0} "${@}"'<p>Would be cleaner if there was mode handling this.<p>#!/usr/bin/env -S argc -e
Okay so this is clever – it's a polyglot, both a valid bash script and a DSL which is interpreted by some binary written in Rust and called at the final "eval $(argc...)" line, where "argc" is the name of the rust binary.<p>Thinking loudly: I was just wondering about debugging (kind of "does this lack source maps?"), but shell never prints out lines at syntax errors, so it does not really matter. One can write "set -e" anyway at the start of the functions in order to catch errors early.
It's an interesting idea but a lot of care is needed to avoid parsing bugs. I.e. the code you are feeding to the shell via "eval" doesn't not get parsed in some way you don't expect. Also, parsing the script source code, need to be careful and clear about the parse rules. In that case, it's not as dangerous since the script source code is presumably not provided by an attacker (otherwise they could just directly run the commands they want).