是否有可能在 Linux (Debian) 中为您编写的 bash 脚本添加“帮助”?我的意思是,通过使用命令 yourscript --help
或 yourscript -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/