linux - 如何添加到 bash 脚本帮助选项 "yourscript --help"

标签 linux bash

是否有可能在 Linux (Debian) 中为您编写的 bash 脚本添加“帮助”?我的意思是,通过使用命令 yourscript --helpyourscript -h

最佳答案

它不一定比这更难。

case $1 in
 -[h?] | --help)
    cat <<-____HALP
        Usage: ${0##*/} [ --help ]
        Outputs a friendly help message if you can figure out how.
____HALP
        exit 0;;
esac

如果您使用getopts进行选项处理,请使用它来识别选项;但操作看起来或多或少相似(IMNSHO getopts 并没有真正通过简单的 while ... shift 循环提供任何东西)。

关于linux - 如何添加到 bash 脚本帮助选项 "yourscript --help",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29285976/

相关文章:

r - Tcl 在 Linux CentOS 7 上无法与 R 一起使用,如何解决?

linux - 将文件名插入 csv 文件的最后一列。

json - 使用 bash 脚本从 API 保存 JSON

linux - bash 条件表达式 -x 可以看作是 if 条件吗?

linux - 比较管道分隔文件并将不匹配的列写入输出文件

ajax - Web 开发的最佳 Linux 发行版?

c++ - Linux TCP 服务器 - 在 C++ 中监听多个端口

linux - 如何按列值分组到行和列标题中,然后对值求和