TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Argc – A handy way to handle sh/bash CLI parameters

36 pointsby TheLocehiliosanabout 3 years ago

5 comments

gkfasdfasdfabout 3 years ago
Very cool. A natural next step would be to auto-generate a completion script.
moondevabout 3 years ago
pretty cool. instead of putting the eval() inside the script a shebang also works.<p>#!&#x2F;usr&#x2F;bin&#x2F;env -S bash -c &#x27;argc -e ${0} &quot;${@}&quot;&#x27;<p>Would be cleaner if there was mode handling this.<p>#!&#x2F;usr&#x2F;bin&#x2F;env -S argc -e
ktpsnsabout 3 years ago
Okay so this is clever – it&#x27;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 &quot;eval $(argc...)&quot; line, where &quot;argc&quot; is the name of the rust binary.<p>Thinking loudly: I was just wondering about debugging (kind of &quot;does this lack source maps?&quot;), but shell never prints out lines at syntax errors, so it does not really matter. One can write &quot;set -e&quot; anyway at the start of the functions in order to catch errors early.
评论 #30570081 未加载
nasabout 3 years ago
It&#x27;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 &quot;eval&quot; doesn&#x27;t not get parsed in some way you don&#x27;t expect. Also, parsing the script source code, need to be careful and clear about the parse rules. In that case, it&#x27;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).
RhysUabout 3 years ago
Feels like <a href="https:&#x2F;&#x2F;github.com&#x2F;docopt&#x2F;docopts" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;docopt&#x2F;docopts</a>