什么是“["?我的“/bin"中的二进制文件文件夹?(MacOS Big Sur M1 芯片) [英] What is the "[" binary file in my "/bin" folder for? (MacOS Big Sur M1 chip)

查看:17
本文介绍了什么是“["?我的“/bin"中的二进制文件文件夹?(MacOS Big Sur M1 芯片)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是操作系统的新手,并试图通过探索我的新计算机来赶上.

I am newbie in Operation System, and trying to catch up by exploring my new computer.

今天早上,我刚刚浏览了bin文件,看到了一个奇怪的文件夹,叫[".这是什么?

This morning, I was just exploring the bin file, and I saw a weird folder called "[". What is this?

我没有在/bin"中创建或安装任何东西.文件夹呢.所以它不是我创造的.什么是["?我的/bin"中的二进制文件文件夹?

I did not create or install anything in the "/bin" folder yet. So it was not created by me. What is the "[" binary file in my "/bin" folder for?

推荐答案

[是测试程序.正如手册页所暗示的那样,它的使用方式类似于

[ is the test program. As the man page suggests, it's used like

[ condition ]

并计算为零(为真)或非零值(为假).对于 macOS 上的 zsh,手册页说 false 由 1 表示.请注意,方括号后面的空格很重要,因为该空格向 shell 表明您要运行 [程序.

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.

尽管存在该程序,但该可执行文件可能并不经常使用.看来您正在使用 zsh,它是 macOS 上的默认 shell.在 zsh 中,[ 是一个优先于 /bin/[ 的内置函数.这可以通过

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/[

内置的手册页可以通过 man zshbuiltins 找到.

The man page for the built-in can be found by man zshbuiltins.

如果你想显式使用 /bin 中的程序,那么你的命令应该是这样的

If you want to explicitly use the program in /bin, then your command should look like

/bin/[ condition ]

示例

假设您正在运行一个要检查条件的 shell 脚本.例如,您要检查文件是否存在.[ 经常用于此目的.这是一个例子

Example

Supposed you're running a shell script where you want to check a condition. For example, you want to check whether a file exists. [ is frequently used for this purpose. Here is an example

if [ -f myFile.txt ]; then
   date > myFile.txt
else
   echo "File was created on $(cat myFile.txt)."
fi

这篇关于什么是“["?我的“/bin"中的二进制文件文件夹?(MacOS Big Sur M1 芯片)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆