[
是测试程序。正如手册页所建议的那样,
[ condition ]
and evaluates to either a zero (for true) or a non-zero value (for false). In the case of zsh on macOS, the man page says that false is represented by 1. Note that the whitespace after the square bracket is important since that whitespace indicates to the shell that you want to run the [
program.
Despite the presence of the program, that executable is probably not used often. It appears that you're using zsh, which is the default shell on macOS. In zsh, [
is a built-in which takes precedence over /bin/[
. This can be verified by
% which -a [
[: shell built-in command
/bin/[
The man page for the built-in can be found by man zshbuiltins
.
If you want to explicitly use the program in /bin
, then your command should look like
/bin/[ condition ]
假设您正在运行要检查条件的Shell脚本。例如,您要检查文件是否存在。[
通常用于此目的。这是一个例子
if [ -f myFile.txt ]; then
date > myFile.txt
else
echo "File was created on $(cat myFile.txt)."
fi
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句