The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
significance of statement nickcarter UNIX for Dummies Questions & Answers 3 02-19-2008 09:48 AM
what is the significance of braces and spaces??? ahmedwaseem2000 Shell Programming and Scripting 3 09-03-2006 09:41 PM
what the significance of ~ BigTool4u2 UNIX for Dummies Questions & Answers 2 04-22-2004 09:56 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-16-2007
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
What is the significance of . / ?

Many scripts are executed in the following way.

. /scriptname

Even when the file does not have execute permission, it can be executed this way. How does this work?
  #2 (permalink)  
Old 07-16-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by krishmaths View Post
Many scripts are executed in the following way.

. /scriptname

Even when the file does not have execute permission, it can be executed this way. How does this work?
In this case, scriptname is passed as an argument to the current shell i.e. you are asking the current shell to execute it.

When you do ./scriptname, you are executing scriptname in a subshell within the current shell.
  #3 (permalink)  
Old 07-16-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
I have script named test.ksh under /tmp directory.


Code:
ls -l test.ksh
-rwx------   1 enaggan  inmalogin      30 Jul 16 11:59 test.ksh

I have execute permisson on it.

Case 1:
I am trying to run the above script by,
cd /tmp
test.ksh
ksh: test.ksh: not found

This doesnot work as we have not added the path /tmp to the PATH varible.

Case 2:
I am trying to run the above script by,
cd /tmp
./test.ksh
Hello World


To run a script that is not present in any of the directories in the PATH variable,we have to explicitly state path of the script.
i.e Either the full path or relative path.
Eg: /tmp/test.ksh or ./test.ksh


Case 3:

In case of we don't execute permisson on the script,
We can pass the name of the script as an argument to ksh.

Example:
ksh test.ksh
Hello World



Code:
 cat /tmp/test.ksh
   #!/bin/ksh
   echo "Hello World"

Hope this clarifies.

Thanks
Nagarajan Ganesan
  #4 (permalink)  
Old 07-16-2007
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
Thanks

Case 3 was what I was looking at. Thanks Nagarajan and Thanks Vino.

Welcoming more discussions on this topic...
  #5 (permalink)  
Old 07-16-2007
bigearsbilly bigearsbilly is offline
Registered User
  
 

Join Date: Feb 2006
Location: Southern England
Posts: 104
well, basically when you source a file like this you are running it in the
context of the current shell.
simply put, if you do
. script you are not running it, you are including it line by line, sort of.
So if you do it from the command line it's as if you have typed the script in manually so all variables, functions etc. will remain once the process is over.

it is generally a way of importing variables functions etc into the current environment or context whatever you like to call it.

a script run normally will do it's own thing without affecting the current
script or environment.

if you get what i mean.
  #6 (permalink)  
Old 07-16-2007
krishmaths krishmaths is offline
Registered User
  
 

Join Date: Sep 2006
Location: Mysore, India
Posts: 191
Thumbs up

@bigearsbilly:

I can relate to what you are trying to explain, as I've applied the same practically without knowing what is actually being done. Its very clear. Thanks for your explanation!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0