参见:What is the Bash equivalent of Python's pass statement
这个“:”冒号用法叫什么?例如:
if [[ -n $STRING ]]; then
#printf "[INFO]:STRING: if -n string: STRING:$STRING \n"
:
else
printf "[INFO]:Nothing in the the string\n"
fi
最佳答案
具体而言,请在 shell 中运行 help :
。它给出:
$ help : :: : Null command. No effect; the command does nothing. Exit Status: Always succeeds.
在单行无限循环中非常有用,例如:
while :; do date; sleep 1; done
同样,您可以使用 true
而不是 :
编写相同的内容,但这更短。
有趣的是:
$ help true true: true Return a successful result. Exit Status: Always succeeds.
根据这个,不同的是:
是“Null command”,
而 true
是“返回成功的结果”。
另一个区别是 true
通常是真正的二进制文件:
$ which true /usr/bin/true
另一方面,which :
没有给出任何结果。 (这是有道理的,作为一个“空命令”。)
无论如何,@Andy是的,这是 this other post 的重复项,这更好地解释了它。
关于bash - bash 中的 ":"被称为什么?冒号用作传递语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26897554/