2

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
10

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.

2

Without -c bash tries to run the argument as its script. The /bin/date is not a bash script, so it fails.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.