For example I have a file named file2
that echoes something.
So in the shell, after typing this
# ./file2
It shows
Permission denied
Where am I wrong here?
You are trying to execute a file and you do not have the right permissions for this. When you create a new Bash script with your text editor (let's say Vim), you should have the following permissions: -rw-r--r--
. As a user, you can then read and write this file, but you cannot execute it with ./
.
If you want to execute a file without changing permissions, you can use the following command: bash myFile.sh
.
If you want to execute a file with ./
, you will have to modify permissions. Something like that is OK: chmod +x myFile.sh
.
If you do not want to struggle with ./
and prefer to call myFile.sh
from anywhere like other built-in commands, move the executable file in a directory that is in your PATH. /usr/local/bin
should be a wise choice. Check your PATH with echo $PATH
, just in case...