【SHELL】[[ ]]条件判断结构()

实测发现 [[ ]]条件判断结构 只支持两级,即if-else非if-elif-else

输入参数包含 ‘arg-m’ 时,会输出 Hit Arg-M 和 Hit Arg-N

[[ ${EXEC_PARAMS[@]} =~ 'arg-m' ]] && echo "Hit Arg-M" ||
[[ ${EXEC_PARAMS[@]} =~ 'arg-n' ]] && echo "Hit Arg-N" ||
echo "Oh Shit"

可实现多级判断

[[ ${EXEC_PARAMS[@]} =~ 'arg-m' ]] && echo "Hit Arg-M" || {
    [[ ${EXEC_PARAMS[@]} =~ 'arg-n' ]] && echo "Hit Arg-N" ||
    echo "Oh Shit"
}
————————

实测发现 [[ ]]条件判断结构 只支持两级,即if-else非if-elif-else

输入参数包含 ‘arg-m’ 时,会输出 Hit Arg-M 和 Hit Arg-N

[[ ${EXEC_PARAMS[@]} =~ 'arg-m' ]] && echo "Hit Arg-M" ||
[[ ${EXEC_PARAMS[@]} =~ 'arg-n' ]] && echo "Hit Arg-N" ||
echo "Oh Shit"

可实现多级判断

[[ ${EXEC_PARAMS[@]} =~ 'arg-m' ]] && echo "Hit Arg-M" || {
    [[ ${EXEC_PARAMS[@]} =~ 'arg-n' ]] && echo "Hit Arg-N" ||
    echo "Oh Shit"
}