为什么`bash <command>` 无法运行?

Tim*_*Tim 3 bash

为什么bash <command>无法运行?

$ bash date
/bin/date: /bin/date: cannot execute binary file

$ /bin/date
Fri Mar 18 05:59:24 EDT 2016

$ bash -c date
Fri Mar 18 06:00:39 EDT 2016
Run Code Online (Sandbox Code Playgroud)

Ste*_*itt 11

来自 手册

如果在选项处理后参数仍然存在,并且 -c没有-s提供选项也没有提供选项,则假定第一个参数是包含 shell 命令的文件的名称。

所以bash date意思是“读取date文件并执行它包含的shell命令”。假设date当前目录中没有文件,bash搜索路径并找到/bin/date哪个是二进制文件而不是shell脚本,因此错误。