The first four parts of my Typesetting Markdown blog describes improving the user-friendliness of bash scripts. In particular, you can use bash to define a reusable script that allows isolating software dependencies, command-line arguments, and parsing.<p><a href="https://dave.autonoma.ca/blog/2019/05/22/typesetting-markdown-part-1/" rel="nofollow">https://dave.autonoma.ca/blog/2019/05/22/typesetting-markdow...</a><p>In effect, create a list of dependencies and arguments:<p><pre><code> #!/usr/bin/env bash
source $HOME/bin/build-template
DEPENDENCIES=(
"gradle,https://gradle.org"
"warp-packer,https://github.com/Reisz/warp/releases"
"linux-x64.warp-packer,https://github.com/dgiagio/warp/releases"
"osslsigncode,https://www.winehq.org"
)
ARGUMENTS+=(
"a,arch,Target operating system architecture (amd64)"
"o,os,Target operating system (linux, windows, macos)"
"u,update,Java update version number (${ARG_JAVA_UPDATE})"
"v,version,Full Java version (${ARG_JAVA_VERSION})"
)
</code></pre>
The build-template can then be reused to enhance other shell scripts. Note how by defining the command-line arguments as data you can provide a general solution to printing usage information:<p><a href="https://gitlab.com/DaveJarvis/KeenWrite/-/blob/main/scripts/build-template?#L186" rel="nofollow">https://gitlab.com/DaveJarvis/KeenWrite/-/blob/main/scripts/...</a><p>Further, the same command-line arguments list can be used to parse the options:<p><a href="https://gitlab.com/DaveJarvis/KeenWrite/-/blob/main/scripts/build-template?#L186" rel="nofollow">https://gitlab.com/DaveJarvis/KeenWrite/-/blob/main/scripts/...</a><p>If you want further generalization, it's possible to have the template parse the command-line arguments automatically for any particular script. Tweak the arguments list slightly by prefixing the name of the variable to assign to the option value provided on the CLI:<p><pre><code> ARGUMENTS+=(
"ARG_JAVA_ARCH,a,arch,Target operating system architecture (amd64)"
"ARG_JAVA_OS,o,os,Target operating system (linux, windows, macos)"
"ARG_JAVA_UPDATE,u,update,Java update version number (${ARG_JAVA_UPDATE})"
"ARG_JAVA_VERSION,v,version,Full Java version (${ARG_JAVA_VERSION})"
)
</code></pre>
If the command-line options require running different code, it is possible to accommodate that as well, in a reusable solution.