[Newbie] scipt permission denied?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
faza

[Newbie] scipt permission denied?

Post by faza »

I just wrote this simple script:
#!/bin/bash

echo hello world
And saved it on the desktop, but when i try to ./Script it says : bash: ./Script: permission denied
Why?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
karlchen
Level 23
Level 23
Posts: 18238
Joined: Sat Dec 31, 2011 7:21 am
Location: Germany

Re: [Newbie] scipt permission denied?

Post by karlchen »

The script is not executable.
Here is one way to solve this:

Code: Select all

cd ~/Desktop
chmod +x Script
./Script
HTH.
Image
The people of Alderaan have been bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine for 792 days now.
Lifeline
Otyugh

Re: [Newbie] scipt permission denied?

Post by Otyugh »

If you know how to navigate through your files with "ls" and "cd" you might like to know that doing "ls -l" displays the files permission.
You'll see a lot of "rwx". R is for read, W is for write, and X for eXecutable.
There is 3 occurence of that. The first is the permission of the "owner of the file" (you, cause you have created your script file !), the second is the right of "your group" and last, "the other rights".

If there is a "-" instead of a "r/w/x", that means that this permission is set as "deny". If you do a "ls -l PATHTOYOURSCRIPT" you'll normally see something beginning like that : -rw-
The first "-" is special. It's saying "this is a file". If not, you'll see a "d" for Directory.
What stands after is what I've explained before. What you want to see now is a beautiful -rwx that allows you to execute the script x)

Chmod is the command that can change that (karlchen instructions : chmod +x PATHTOYOURSCRIPT !).
Habitual

Re: [Newbie] scipt permission denied?

Post by Habitual »

bash ~/Desktop/.Script
will run it if it's not executable.
Locked

Return to “Scripts & Bash”