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 08-29-2005, 12:53 AM   #1
seeDubya
LQ Newbie
 
Registered: Aug 2005
Location: Virginia, US
Distribution: RedHat9
Posts: 5

Rep: Reputation: 0
Question Why prefix shell script with "./" ?


Can someone explain or point me to documentation/resource on prefixing a shell script with a period and forward slash? I see this often when executing installation scripts but am finding it difficult to Google an answer!

In an attempt to get some useful response I have written a simple script that echoes to the console. Simply calling the script, "test", provides no response at all. Calling "sh test" executes fine. Calling "./test" produces "Permission denied.".
 
Old 08-29-2005, 01:09 AM   #2
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
To execute any file (well, any executable file, whether it's a shell script, program, etc.), you type the full path to that file. For example,

Code:
/usr/local/bin/gaim
to run the program "gaim" located in the directory "/usr/local/bin"

If you're already in the directory "/usr/local/bin" then you can abbreviate the full path using a single dot, which stands for the current directory. Therefore, in:

Code:
cd /usr/local/bin
./gaim
"./gaim" gets expanded to "/usr/local/bin/gaim" since "/usr/local/bin" is your current location.

There is one exception to this rule. If you type the name of a file/program without using the full path, the shell looks for it in the directories in your PATH environment variable and, if it finds it there, runs it. Type "echo $PATH" to see all the directories in your PATH. Since "/usr/local/bin" is in your PATH, you can simply type "gaim" and it will be executed.

When all else fails and you want to be sure a particular script is being executed, type the full path to make sure it's not running something else with the same name in one of the directories in your PATH.

EDIT:
To see why you're getting the permission denied error, type "ls -l test" to see the permissions of the script. You probably haven't set it to be executable (it's just a normal file that can't be run unless you let people execute it). Try "chmod 744 test" to change that.

Last edited by jrdioko; 08-29-2005 at 01:11 AM.
 
Old 08-29-2005, 01:14 AM   #3
seeDubya
LQ Newbie
 
Registered: Aug 2005
Location: Virginia, US
Distribution: RedHat9
Posts: 5

Original Poster
Rep: Reputation: 0
Great explanation. Thank you for your time.
 
Old 08-29-2005, 01:15 AM   #4
hardian_97
LQ Newbie
 
Registered: Jul 2005
Location: Indonesia
Posts: 23

Rep: Reputation: 15
if you are trying to execute shell script using ./ and it gave error respond such as permission denied, then try to take a look the file permission of your "test" file. I'm guessing that the execute permission is not active yet.

ls -la | grep test --> to see the permission of file test

usually look like this: -rw-r--r--

if this is the case, then you need to change the permission to activate the execute permission.
try this: chmod 744 test

this will change the permission to -rwxr--r--

then try ./test

it should work, i think...

Cheers,
Hardian_97
 
Old 08-29-2005, 01:15 AM   #5
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
No problem, welcome to LQ.
 
Old 08-29-2005, 01:53 AM   #6
seeDubya
LQ Newbie
 
Registered: Aug 2005
Location: Virginia, US
Distribution: RedHat9
Posts: 5

Original Poster
Rep: Reputation: 0
hardian_97,

Thanks. It was the permissions. I suppose that calling "sh test" is utilizing read on test and execute on sh. That was throwing me off a bit.
 
  


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
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
shell script with "netcat > file" at boottime trajjm Programming 3 10-10-2005 06:54 AM
Starting Java from shell script (Exception in thread "main") rolf_mueller Linux - Software 5 10-30-2004 02:11 AM
1. shell script "find and replace" on text 2. java GUI application randomx Programming 4 03-05-2004 01:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:16 PM.

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