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.

Ask HN: Unix Utility Development Conventions

6 pointsby rayascottover 5 years ago
I&#x27;m slowly hacking away at a zsh script that shows some promise as a command line tool. I want to learn more about the conventions regarding command line tool development in Unix (and&#x2F;or macOS), but don&#x27;t really know where to look for this information.<p>What is the correct way, or convention, to specify and parse command line arguments, for example? How should I package my tool? What is the best way to handle deployment of the various aspects of my tool, for example the man page, or configuration settings? How should I handle the upgrade process?<p>Smaller details, like should I store my source code in the repo with execute permissions turned on, or should I only turn on those permissions when the files are deployed on the user&#x27;s machine? What group should I set as the default for my executable files?<p>Does anyone know any great resources out there that address these issues?

2 comments

jolmgover 5 years ago
&gt; What is the correct way, or convention, to specify and parse command line arguments, for example?<p>I often use variations of this pattern:<p><pre><code> version=1.0.0 usage() { cat &lt;&lt; EOF USAGE: $0 {{-f|--file} &lt;filename&gt;} Some description. OPTIONS -h, --help Display this help. -v, --version Display version. -f &lt;filepath&gt;, --file &lt;filepath&gt; Specify input file. EOF } while (( $# )); do case &quot;$1&quot; in -h|--help) usage exit ;; -v|--version) printf &quot;%s\n&quot; &quot;$version&quot; exit ;; -f|--file) input_file=&quot;$2&quot; shift ;; *) &gt;&amp;2 printf &quot;Unknown option: %s\n&quot; &quot;$1&quot; &gt;&amp;2 usage exit 1 ;; esac shift done </code></pre> There are standard guidelines[1][2].<p>[1] <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;prep&#x2F;standards&#x2F;standards.html#Command_002dLine-Interfaces" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;prep&#x2F;standards&#x2F;standards.html#Command_00...</a><p>[2] <a href="https:&#x2F;&#x2F;cli-guide.readthedocs.io&#x2F;en&#x2F;latest&#x2F;design&#x2F;guidelines.html#id1" rel="nofollow">https:&#x2F;&#x2F;cli-guide.readthedocs.io&#x2F;en&#x2F;latest&#x2F;design&#x2F;guidelines...</a>
tannhaeuserover 5 years ago
<a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;basedefs&#x2F;V1_chap12.html#tag_12_01" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;basedefs&#x2F;V1...</a><p><a href="http:&#x2F;&#x2F;catb.org&#x2F;~esr&#x2F;writings&#x2F;taoup&#x2F;html&#x2F;ch10s05.html" rel="nofollow">http:&#x2F;&#x2F;catb.org&#x2F;~esr&#x2F;writings&#x2F;taoup&#x2F;html&#x2F;ch10s05.html</a>
评论 #21240951 未加载