命令的含义是“不执行任何操作".在Bash中有条件吗? [英] What command means "do nothing" in a conditional in Bash?
本文介绍了命令的含义是“不执行任何操作".在Bash中有条件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有时在进行条件查询时,我不需要代码执行任何操作,例如,在这里,我希望Bash在 $ a
大于"10"时不执行任何操作,如果 $ a
小于"5",否则打印"2":
Sometimes when making conditionals, I need the code to do nothing, e.g., here, I want Bash to do nothing when $a
is greater than "10", print "1" if $a
is less than "5", otherwise, print "2":
if [ "$a" -ge 10 ]
then
elif [ "$a" -le 5 ]
then
echo "1"
else
echo "2"
fi
但这会导致错误.有没有什么不做的命令也不会减慢我的脚本的速度吗?
This makes an error though. Is there a command which will do nothing and also not slow down my script?
推荐答案
shell中的no-op命令是:
(冒号).
The no-op command in shell is :
(colon).
if [ "$a" -ge 10 ]
then
:
elif [ "$a" -le 5 ]
then
echo "1"
else
echo "2"
fi
来自 bash手册:
:
(冒号)
除了扩展参数和执行重定向之外,什么也不要做.返回状态为零.
:
(a colon)
Do nothing beyond expanding arguments and performing redirections. The return status is zero.
这篇关于命令的含义是“不执行任何操作".在Bash中有条件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文