3

I have a rooted phone, and I was playing around with Terminal Emulator. I tried writing a simple shell script (test.sh) :

#!/bin/sh
echo "Hello, World!" 

Then I opened terminal emulator, cd'd to the directory my script was in, and typed:

./test.sh

and I got a "permission denied" error. So I tried:

su
./test.sh

Somehow, still permission denied. So I tried (still as root) :

chmod 775 test.sh
busybox chmod 775 test.sh
busybox chmod +X test.sh

None of the 3 gave errors, but ./test.sh still gave permission denied! As a last resort I tried

sh test.sh

That ended up working. Finally.

I'm curious why permission was denied for my own shell script chmodded to 775 when run as root. How can permission be denied for anything as root? How can I fix this and make ./test.sh work?

  • 3
    This largely depends on where in the filesystem the script is, so if you could add that it would likely be helpful. If it's on the SD card (or whatever your device uses as "external storage") then you'd probably have to remount the partition or something, because Android mounts it with the noexec flag by default. – eldarerathis Aug 7 '13 at 19:32
  • It is on the SD card. I'll try remounting. – DankMemes Aug 7 '13 at 20:08
  • busybox chmod +X test.sh is wrong, you’d want to be using +x (lower-case). Anyway, 775 ends up being the same, so it’s the noexec issue. – mirabilos Mar 6 '14 at 10:20
3

Execute permissions on the SDCard is blocked for that reason.

See this:

/dev/block/vold/179:1 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,**noexec**,relatime,uid=1000,gid=1015,fmask=0602,dmask=0602,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0

The noexec part of this line emphasized with two asterisks is the key to prevent any execution of scripts/binaries from the SDCard.

Have a funny feeling this was answered before...deja-vu

Edit

Yup @Izzy has answered this before and here as well.

| improve this answer | |

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