I have a weird problem, I cant execute bash script even as basic as:
#!/bin/bash
echo "me"
I am saving it as a test.sh and then do chmod 755 test.sh and once run ./test.sh getting:
bash: ./test.sh: Permission denied
Any ideas what could be causing this?
To give root privileges to a user while executing a shell script, we can use the sudo bash command with the shebang. This will run the shell script as a root user. Example: #!/usr/bin/sudo bash ....
Usually, you get the error bash permission denied when running some script/file that does not have execute permissions. All you need to do is to change file permissions and add executive one.
The Bash permission denied error indicates you are trying to execute a file which you do not have permission to run. To fix this issue, use the chmod u+x command to give yourself permissions. If you cannot use this command, you may need to contact your system administrator to get access to a file.
Check the script is being run by root user #!/bin/bash # Init FILE="/tmp/out. $$" GREP="/bin/grep" #.... # Make sure only root can run our script if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" 1>&2 exit 1 fi # ...
That can happen if you have mounted the file system with the "noexec" option. You should remove it.
Script needs be executable. Use this:
chmod +x <script-name>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With