I'm using git bash
on Windows. I want to run ls
command with bash
. I can run ls
separately like this:
$ ls
f1 f2
However, when I try with bash
, I get the error:
$ bash ls
/usr/bin/ls: /usr/bin/ls: cannot execute binary file
But if I create my script it works fine:
$ echo "echo \$@" > my.sh && bash my.sh
What can be the problem?
Best Answer
From the fine manual for
bash(1)
:Does
ls
contain shell commands? No, it is a binary file.bash
squawks about this fact and fails.A
strace
may help show what is going on:The
alog
file can get a bit messy, but showsbash
looking forls
in the current working directory—a security risk if someone has placed a naughtyls
file somewhere!—and then does aPATH
search:As to why this could be a security risk, if you run
bash somecmd
from the wrong directory where someone has created als
(or some other known command due to a bug in a script):