gpt4 book ai didi

bash - 为什么 bash 的流控制结构不一致?

转载 作者:行者123 更新时间:2023-11-29 08:57:24 25 4
gpt4 key购买 nike

<分区>

我正在自学 bash,并使用 Learning the bash Shell这样做。

我注意到在流程控制中我们定义了一个 if/else 语句:

if [ statement_is_true ]; then
# do stuff here
elif [ some_other_statement]; then
# other thing
else
# if all else fails
fi

和这样的案例陈述:

case $expr in
case1 )
;;
case2 )
;;
esac

但是 for 循环可以定义为

for i in $list;
do
# something cool with the various $i
done

和一个 while 循环

while [ condition ]; do
# something that loops
done

为什么 forwhileuntil 循环的结束用 done 表示而不是 rofelihwlitnu,分别类似于 if/ficase/esac构造? (或者,为什么是 if/fi 而不是 if/done

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com