Bash – Why Does Bash Command Fail to Run?

bash

Why does bash <command> fail to run?

$ 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

Best Answer

From the manual:

If arguments remain after option processing, and neither the -c nor the -s option has been supplied, the first argument is assumed to be the name of a file containing shell commands.

So bash date means "read the date file and execute the shell commands it contains". Assuming there is no date file in the current directory, bash searches the path and finds /bin/date which is a binary rather than a shell script, hence the error.

Related Question