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?
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...
 
    
    . refers to the current working directory and .. refers to the parent directory. So ./file2 means "execute the file named file2 in the current directory". Without the ./, the shell will search for file2 in all the directories of your PATH. If you want to execute it, add the execute bit with chmod +x ./file2 and try again. If you just want to view it, try less ./file2
