Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This problem has bugged me so much and I can't find a solution. Sorry in advance if it is a newbie question.

Let's say I have a file called run.sh that contains:

#! /bin/sh -x

x-www-browser index.html

And ls -l run.sh says:

-rwxr-xr-x 1 myusername myusername 39 Jan  9 19:32 run.sh

And ./run.sh says:

bash: ./run.sh: Permission denied

Why does it not work? Why does sh -x run.sh work perfectly?

More info, since it's not so easy apparently

If I do a sudo, it will not output an error, but won't do anything either.

myusername@crunchbang:/mnt/data$ sudo ./run.sh
[sudo] password for myusername: 
share|improve this question
up vote 12 down vote accepted

The filesystem run.sh is on has been mounted noexec.

share|improve this answer
This is the file system I'm in, copied from /etc/fstab, is it there I should look? /dev/sda4 /mnt/data auto rw,user,auto 0 0 – fury Jan 10 '12 at 0:53
No, you should always look at the most accurate view, available via mount. – Ignacio Vazquez-Abrams Jan 10 '12 at 1:05
You're right!!! mount command says /dev/sda4 on /mnt/data type ext4 (rw,noexec,nosuid,nodev), but how can it be? – fury Jan 10 '12 at 1:11
As described in the mount(1) man page, user implies noexec,nosuid,nodev. You will need to explicitly add exec to the mount options to override this. – Ignacio Vazquez-Abrams Jan 10 '12 at 1:14
It now works after changing /etc/fstab and rebooting. Thank you so much, I would never had realized that there were aliases for multiple values. – fury Jan 10 '12 at 1:26

My guess is that the #! line has some weird character on it, perhaps an ASCII Nul or other non-printing character, a backspace-something maybe. Some shells have had a problem with MS-DOS/Windows two-byte (carriage-return linefeed) end-of-line markers. Modern editors can examine files and decide whether they're Unix-style (linefeed) end-of-lines, or Windows style (and maybe even Mac style) text files. Maybe you've gotten your editor mixed up and written out a Windows text file.

This causes the kernel to not find whatever "executable" is so specified, and it claims that it can't execute the non-existent "executable".

share|improve this answer
I tried to investigate what you explained, and rewrote from scratch the file, without copy-pasting, with a linux editor. I also tried to put an empty line at the end of the file. But no luck. – fury Jan 10 '12 at 1:02
This usually gives a "bad interpreter" error, not a "permission denied". – Ignacio Vazquez-Abrams Jan 10 '12 at 1:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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