LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-27-2009, 04:25 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
Strange Query


Hi guys i have created a script project.sh which has no execute permission yet.
But i m still able to execute it by using
sh project.sh

when i use ./project.sh it says -bash: ./project.sh: Permission denied

How?

[root@test milind]# ls -ltr
total 24
-rw-r----- 1 root root 100 Oct 27 13:30 project.sh
 
Old 10-27-2009, 04:39 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Because of the way the shell's search for executable commands works; commands must have execute permission and either a) be in a directory listed in $PATH or b) named with a full path. A full path must begin with /, . or ~

I the case of your experiment this one fails because there is no execute permission
Code:
./project.sh
and this one works because a) sh satisfies both the "have execute permission" and "be in a directory listed in $PATH" and b) sh will try to run any script it can find and read (no execute permission required)
Code:
sh ./project.sh
 
Old 10-27-2009, 04:42 AM   #3
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
you need to have excute bit set to do "cd"
 
Old 10-27-2009, 04:57 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by asimba View Post
you need to have excute bit set to do "cd"
That's right but what is the relevance to pinga123's question?
 
Old 10-27-2009, 05:21 AM   #5
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
Quote:
Originally Posted by catkin View Post
That's right but what is the relevance to pinga123's question?

I did not read it carefully - entirely my fault.

I thought he was trying to change directory to and all he had was read and write rights.

I apologize.
 
Old 10-27-2009, 05:32 AM   #6
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
Quote:
Originally Posted by catkin View Post
Because of the way the shell's search for executable commands works; commands must have execute permission and either a) be in a directory listed in $PATH or b) named with a full path. A full path must begin with /, . or ~

I the case of your experiment this one fails because there is no execute permission
Code:
./project.sh
and this one works because a) sh satisfies both the "have execute permission" and "be in a directory listed in $PATH" and b) sh will try to run any script it can find and read (no execute permission required)
Code:
sh ./project.sh
In addition to this -

as you pointed sh ./project.sh would be right way to do.

He may have project.sh in multiple directories (talking about possiblities )



sh project.sh will execute the "first" project.sh found in path variable.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
strange AAAA lookup query xnetua Linux - Networking 4 09-06-2009 10:11 AM
interesting MySQL query/view query :s mjh Programming 3 03-25-2008 08:30 AM
mysql use output of one query in another query secretlydead Programming 2 11-19-2007 02:25 AM
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 07:36 PM
Sound Issues with XMMS/ mpg123 strange (strange noises) thegreatbob Linux - Software 0 06-25-2004 04:18 PM


All times are GMT -5. The time now is 11:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration