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

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

问题描述

我是Operating System的新手,并试图通过探索我的新计算机来赶上来.

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天全站免登陆