加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

unix – 如何添加一个帮助方法到shell脚本?

发布时间:2020-12-15 16:28:07 所属栏目:安全 来源:网络整理
导读:如何检查-h属性是否已传递到shell脚本中?我想显示一个帮助消息,当用户调用myscript.sh -h。 这里是一个bash的例子: usage="$(basename "$0") [-h] [-s n] -- program to calculate the answer to life,the universe and everythingwhere: -h show this he
如何检查-h属性是否已传递到shell脚本中?我想显示一个帮助消息,当用户调用myscript.sh -h。
这里是一个bash的例子:
usage="$(basename "$0") [-h] [-s n] -- program to calculate the answer to life,the universe and everything

where:
    -h  show this help text
    -s  set the seed value (default: 42)"

seed=42
while getopts ':hs:' option; do
  case "$option" in
    h) echo "$usage"
       exit
       ;;
    s) seed=$OPTARG
       ;;
    :) printf "missing argument for -%sn" "$OPTARG" >&2
       echo "$usage" >&2
       exit 1
       ;;
   ?) printf "illegal option: -%sn" "$OPTARG" >&2
       echo "$usage" >&2
       exit 1
       ;;
  esac
done
shift $((OPTIND - 1))

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读