Permission denied when running .sh scripts

./geany_run_script.sh: 5: ./geany_run_script.sh: ./Area_circumference: Permission denied

program exited with code: 126. This problem always occur when I try to execute my code. What might be the solution?


Here's a link which explains about Changing file permission (and ownership)

If you want to skip these (for now of course), you can create a directory/folder in your user-home directory and work on your C programmes (or others) there.


You can open the terminal (press Ctrl + Alt + T) and cd to the target directory:

cd /path/to/target

To give the file "the_file_name" execute permission (if the file-system allows you with the RW rights):

chmod +x the_file_name

You need to give execute and read permissions. Follow this:

chmod u+r+x filename.sh

./filename.sh

When we make a new script file then by default it has read and write permission. But if we want to execute them, then we should give execute permission as shown above.

Execution bit alone is not enough for shell scripts, one must be able to read the file as well to execute it (contrary to binaries which only need the execute permission bit)


Open your terminal application by pressing CTRL + ALT + T or with the apposite shortcut on the graphical enviroment (like Terminal or xTerm).
In the uniform window which appears on the screen you'll see a blinking character, it's the terminal cursor: simply click on the window and write to enter text (typically commands) and press ENTER to confirm the input.
Before the cursor there is always listed your current position on the file system from the root directory ("/") and your home (where your personal files are) is called "~".
To change directory/folder use cd EXISTENTFOLDER (replace EXISTENTFOLDER with the folder name); if you feel lost, simply type cd to return to your home directory in a blink!
Now let's solve your problem:

  1. Use the cd command to find the directory with your source code. Use TAB to help you. If you execute ls -lh, you'll see a list of possible paths to follow and files to execute.

  2. When you've find the blocked file execute chmod +x FILENAME (replace FILENAME with the name of your source code file).

  3. If you have multiple blocked files execute chmod +x * to unlock all files in the current directory. Never chmod +x dangerous or insecure files.

  4. Execute ./FILENAME YOUREVENTUALARGUMENTS to execute your executable file.

  5. Remember that if your compiled program tries to read/write outside your home directory you'll need to execute it as root by using sudo ./FILENAME YOUREVENTUALARGUMENTS.

If you want to have a manual for a command execute man COMMAND (replace COMMAND with the exact command name, Linux is case sensitive).

Some shells have an Open terminal here command to simplify your life, search for it in the future and remember that the command shell can be your best friend, if you use it well. :-D

It's all. If you need more help comment under here.
If I'm helping you press the UP arrow on the left; if you solve mark this answer as best answer.

Have a nice experience on Linux & Ubuntu.