Unable to Run Shell Scripts

BriceH

Registered
I'm working on learning shell scripting, and I made a shell script named helloworld.sh with the following code:
Code:
#!/bin/sh
echo Hello World

It's on my desktop, so in Terminal I put in the following commands to try to run it:
cd ~/Desktop
./helloworld.sh


When I do that, I get the following message:
-bash: ./helloworld.sh: Permission denied


What's the problem? How do I run my shell script?
 
The error message tells it. You do not have permission. Ok, since you created the file, it is your file and you have permission to read and edit it, but not to execute it. Normally text files are not to be executed, so you have to make it executable. Type:


chmod u+x ./helloworld.sh


and then you should be able to execute the file.

The chmod -command changes files permissions. "x" means that it can be executed. u+x means that your (u is for user) permission is changed, but not others.
 
The error message tells it. You do not have permission. Ok, since you created the file, it is your file and you have permission to read and edit it, but not to execute it. Normally text files are not to be executed, so you have to make it executable. Type:


chmod u+x ./helloworld.sh


and then you should be able to execute the file.

The chmod -command changes files permissions. "x" means that it can be executed. u+x means that your (u is for user) permission is changed, but not others.
If I type
chmod x ./helloworld
will it change permissions for everyone?
 
No, chmod x ./helloworld does not, but chmod +x ./helloworld does. (I guess the reason for + is that you can use chmod -x ./helloworld to remove the rights.)
 
Back
Top