Glam Prestige Journal

Bright entertainment trends with youth appeal.

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.txt

However, I continue to get the following error when running from command line:

Comand

./bash_script1.sh

Error

-sh: ./bash_script1.sh: Permission denied

When 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

5

1 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 /home

To make the change persistent, you will need to modify your /etc/fstab file and remove the noexec mount option for this block device.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy