A little script of mine on a mounted windows partition refuses to be executed directly (shebang is #!/bin/bash), but interestingly calling it with bash/sh works. The script is simply a collection of grep and sed commands.

The drive is mounted with full rights:


Hence, for the the file got

-rwxrwxrwx 1 root root

for the file.

What's going on there?


Most probably the windows partition is mounted with the noexec flag on. You can confirm in the output of:


In the output you will probably see something like (rw,noexec) at the end of the line. The noexec flag is not a default, so this usually happens when it is configured explicitly to mount it that way.

When you run the script with bash /path/to/script.sh it works, because in that case you're executing not the script, but you're executing bash, which interprets the script given in its argument.

As an additional note:

but interestingly calling it with sh works.

Since the script has the shebang #!/bin/bash, you should use bash instead of sh to execute it. The author of the script probably used this shebang for a reason, and some implementations of sh (or whatever it's linked to in your system) may not support some Bash features.

Finally, to be able to execute the script directly, you could try to mount the drive with exec flag instead of noexec, but first think about whether that's really a good idea or not. The default of mounting with noexec is for a safety feature, to prevent accidental execution of potentially harmful files coming from untrusted sources. I don't think you should change that. Just run with bash.

| improve this answer | |
  • I added the line with which I mount the drive to the question. I do not specify the noexec option, but I am not sure whether it is maybe included in one of the other options. – MERose Dec 20 '14 at 12:07
  • Run the mount command and find the line of the mount point. I bet it has noexec written on it. If you mount the drive manually, you can specify the exec flag explicitly. But as I explained, I don't recommend to do that. – janos Dec 20 '14 at 12:11
  • Okay, then I'll leave it at it's current state and will run my scripts with sh/bash. – MERose Dec 20 '14 at 12:15
  • 3
    @MERose - the user option implies noexec. From man mount user: Allow an ordinary user to mount the filesystem. The name of the mounting user is written to mtab (or to the private libmount file in /run/mount on system without regular mtab) so that he can unmount the filesystem again. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid). – mikeserv Dec 20 '14 at 14:50

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.