Shell script not running as by "./" but it runs by "sh"
Solution 1
even if your "chmod" returns success, the execute bit does not really get turned on, as "ls" shows, therefore I conclude something is transparently preventing you from changing the file mode on the filesystem.
what does "lsattr Script.sh" shows?
can you put the script into a ramdrive or another filesystem on the same host and try again?
Solution 2
Your script does not have the "execute" rights set for anybody. Try:
chmod u+x Script.sh
and the owner of the file should be able to start it with ./Script.sh
Similarly,
chmod g+x Script.sh
chmod o+x Script.sh
work if you want the group (g) or anybody (o) to be allowed to execute it.
pRAShANT
Updated on September 18, 2022Comments
-
pRAShANT about 1 year
I am running a script on arm target board as a super user, i.e., as a root user. But the script is not executing if i run it with following syntax
root@freescale$ ./Script.sh -sh: ./Script.sh: Permission denied
I already gave the read and execute permissions(+rx) by using chmod command. On executing "ls -l" command I get following attributes
root@freescale$ ls -l | grep Script.sh -rw-rw-rw- 1 root root 362 Jul 2 08:47 Script.sh
"x" is not there in the file attributes column, whereas the chmod command executed successfully. On the other hand, this script runs when I run it as
root@freescale$ sh Script.sh
Can anyone help me to answer this situation?
-
pRAShANT over 10 yearsIt gives following error :
lsattr: Inappropriate ioctl for device While reading flags on Script.sh
-
pRAShANT over 10 yearsI got success status (i.e 0) on performing
echo $?
-
pRAShANT over 10 yearsI tried it but its still the same, no change
-
pRAShANT over 10 yearsWell, I have placed it on a flash drive (type vfat) and mounted on /mnt partition. And the rootfs I am using is UBIFS. I am running it directly from the flash drive.On other system it runs fine without any issue
-
ssssteffff over 10 years
-
Costin Gușă over 10 yearswhat is the output of "mount" command?
-
Costin Gușă over 10 yearsI was able to directly run a .sh script by mounting with umask=000 (as described in the second thread posted by @ssssteffff) - ie "mount -o umask=000 -t vfat [...]" Can you do the same and re-run ls?
-
pRAShANT over 10 years@Costin Gușă: O/P of mount command
rootfs on / type rootfs (rw) ubi0:gpmi-nfc-general-use on / type ubifs (rw,relatime) sys on /sys type sysfs (rw,relatime) tmpfs on /dev type tmpfs (rw,relatime,mode=755) ... /dev/mtdblock4 on /mnt/mtdblock4 type vfat (ro,relatime,fmask=0022,dmask=0022,codepage=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro) /dev/sda1 on /mnt/usb/sda1 type vfat (rw,nosuid,nodev,noexec,noatime,fmask=0111,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=ascii,shortname=mixed,quiet,flush,errors=remount-ro)
-
Costin Gușă over 10 yearsare you able mount it as described above?
-
pRAShANT over 10 years@are you able mount it as described above? – Costin Gușă : Yes, it was self detected and mounted in a location /mnt/usb/sda1/<flashdrive content>
-
Costin Gușă over 10 yearsyou can run it with sh because sh is in fact something like /bin/sh and Script.sh is the argument to /bin/sh which is already executable. so either run via sh or mount with exec (which is among default options) and umask=000 or whatever mask you need as long as it preserves the executable flag
-
pRAShANT over 10 yearsyes, i haven't thougt of it! Anyways Thanks! to both Costin Gușă and ssssteffff
-
Shayan about 4 years
chmod 755 ./Script.sh
did the job for me