I have a foo.sh file in my current directory. If I try to run ./foo.sh, I get:-bash: ./foo.sh: /bin/sh: bad interpreter: Permission deniedBut if I run /bin/sh ./foo.sh then it runs fine.How can I fix this so I can just run ./foo.sh and it automatically runs it with /bin/sh?Edit: Okay, this is Chrome OS and this particular folder is mounted with noexec. Apparently that foils the ability to just run ./foo.sh; but why? Why can I still run sh foo.sh to achieve the exact same thing? What security, then, does noexec give?
Bash won't execute files
bash;chrome os
The noexec flag will appropriately apply to scripts, because that would be the expected behavior.However, setting noexec only stops people who don't know enough about what they're doing. When you run sh foo.sh you're actually running sh from its default location (probably /bin) which is not on a filesystem mounted with noexec.You can even get around noexec for regular binary files by invoking ld directly.cp /bin/bash $HOME/lib/ld-2.7.so $HOME/bashThis will run bash, regardless of wether or not it's on a filesystem mounted with noexec.