我很好奇是否有与 PowerShell 的“切换”命令等效的命令,可以让您使用输入进行操作,而不是使用大量“if 语句”
Dop*_*oti 11
如果您正在查看变量来确定流量,则需要使用case语句。
case "$var" in
val1)
do_something
;;
val2)
do_something_else
;;
esac
Run Code Online (Sandbox Code Playgroud)
如果您希望以交互方式获取用户输入,则还需要使用select语句。
select action in proceed ponder perspire quit; do
case "$action" in
proceed)
go_on_then
;;
ponder)
have_a_think
;;
perspire)
exude_salty_secretions
;;
quit)
break
;;
esac
done
Run Code Online (Sandbox Code Playgroud)