image
image

Go Back   macosx.com > Mac Help Forums > Mac OS X System & Mac Software

Reply
 
LinkBack Thread Tools
  #1  
Old August 24th, 2009, 08:50 AM
BriceH's Avatar
Registered User
 
Join Date: Jul 2009
Posts: 46
Thanks: 3
Thanked 1 Time in 1 Post
BriceH is on a distinguished road
Angry Unable to Run Shell Scripts

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?
Reply With Quote
  #2  
Old August 24th, 2009, 11:56 AM
Registered User
 
Join Date: Mar 2005
Posts: 267
Thanks: 0
Thanked 6 Times in 6 Posts
artov is on a distinguished road
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.
Reply With Quote
  #3  
Old August 24th, 2009, 12:32 PM
BriceH's Avatar
Registered User
 
Join Date: Jul 2009
Posts: 46
Thanks: 3
Thanked 1 Time in 1 Post
BriceH is on a distinguished road
Quote:
Originally Posted by artov View Post
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?
Reply With Quote
  #4  
Old August 25th, 2009, 10:43 AM
Registered User
 
Join Date: Mar 2005
Posts: 267
Thanks: 0
Thanked 6 Times in 6 Posts
artov is on a distinguished road
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.)
Reply With Quote
Reply

Bookmarks

Tags
shell script problem

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump


All times are GMT -5. The time now is 03:47 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
Copyright 2000-2010 DigitalCrowd, Inc.