私は最近 getopts を使用しており、すべてをセットアップしました。問題があります。誰かがコマンド ラインに引数を入力しない場合に、ヘルプ テキストが表示されるように機能させたいと考えています。
$ ./script
$ help: xyz - argument must be used.
これが私が現時点で持っているものです。
#!/bin/bash
function helptext {
# ...
}
function mitlicense {
# ...
}
while getopts "hl" opt; do
case $opt in
h) helptext >&2
exit 1
;;
l) mitlicense >&2
exit 0
;;
\?) echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:) echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
*) helptext >&2
exit 1
;;
esac
done