I am aware that there are similar posts but I have followed what they have done but continue to get the same problem of permission denied when trying to execute my bash script.
I modified my files with command for example:
chmod u+x bash_script1.sh and obtained the following after:
-rwxr--r-- 1 user group 1947 Jun 18 16:04 bash_script1.sh
-rwxr--r-- 1 user group 2430 Jun 18 15:59 bash_script2.sh
-rw-r--r-- 1 user group 1 Jun 18 10:57 runs.txtHowever, I continue to get the following error when running from command line:
Comand
./bash_script1.shError
-sh: ./bash_script1.sh: Permission deniedWhen I run the following command below, I don't get the error but I don't want to use bash to run my script:
bash bash_script1.sh#!/usr/bin/env bash is placed at my heading
51 Answer
As we can see from the output of findmnt -T ., the filesystem on which the script is stored is mounted with the noexec option. This prevents scripts (as well as binary executables) from being executed directly, whereas bash bash_script1.sh still works because the bash executable is stored elsewhere and only needs to read the script.
To modify the behavior temporarily you can use the mount command:
sudo mount -o remount,exec /homeTo make the change persistent, you will need to modify your /etc/fstab file and remove the noexec mount option for this block device.