In Chrome OS, Bash won't execute my script. How do I get Bash to run my script?

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 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/ $HOME/bash

This will run bash, regardless of whether or not it's on a filesystem mounted with noexec.

You can also get this error (or a very, very similar message) if you try to execute a file with MS-DOS 2-byte (carriage-return linefeed) line endings.

Vim is so smart these days, that it doesn't neccessarily show you the carriage returns as '^M'. So you can get fooled if you don't check what Vim thinks the "file format" is and just rely on the on-screen-appearance.

In this case the "#!/bin/sh^M" causes the kernel to try to find "/bin/sh^M", which it can't. Bad interpreter, indeed.

If you have the option to run the script or program from a USB stick (or other removable media), you can try unmounting and manually re-mounting it:

  1. Plug in USB stick

  2. Find USB stick device with $ mount

  3. Take note of it; let's assume it is /dev/sdb1

  4. Unmount USB stick:

    $ cd /media/removable
    $ sudo umount mountpoint

Finally, re-mount USB stick:

$ sudo mount /dev/sdb1 mountpoint

With mountpoint the USB stick's mount name



Chrome Os