我有我的问题在我的脚本优先。 例如,当我调用我的脚本./script -q -h时,它应该返回应该比其他人有更重要优先级的h选项。我的代码如下:Bash脚本 - 如何使选项优先级比别人更重要
#!/bin/bash
function usage
{
echo "Echoing login, name, surname of the invoker
where:
-h help
-q quit(don't proceed script)"
}
function invalid
{
echo "Invalid argument!
"
usage
}
while [ "$1" != "" ]; do
case $1 in
-h | --help) usage
exit
;;
-q | --quit) exit
;;
*) invalid
exit 1
esac
shift
done
echo $USER
getent passwd $USER | cut -d: -f5 | cut -d, -f1
为什么您需要一个退出选项?对于大多数交互式工具,完成时退出不是可选的。 – tripleee
这只是一项功课。我还需要在tcsh中执行相同的脚本,并且不知道如何执行此操作。看来,例如tcsh没有功能。 – wegtis
@triplee -q选项的地方可能是一些服务的管理工具,其中q可被视为关闭该服务。或者启动服务,读取输入文件并保持对新输入文件的轮询运行,除非您已提供-q选项。或'do_a_lot; read_options; do_more_when_not_quit'。 –