aspose file tools*
The moose likes Linux / UNIX and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "" . "  used in front of shell scripts" Watch "" . "  used in front of shell scripts" New topic
Author

" . " used in front of shell scripts

Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
Hi,
Can anyone please tell me why do we use " . " in front of any shell script.
For example if i have a shell script abc.sh

while executing it
how is A output different from B?
A) $ abc.sh

B) $ .abc.sh


Thanks....


Man Suraj
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

There's a space between the dot and the script name.

The dot is a shortcut for the "source" built-in command. "source" reads the commands in the shell script into the current shell and executes them. Executing a script directly (i.e., your option B) launches a separate instance of the shell, which then executes the script. In option "A", variables set by the script will persist in the current shell; in option "B", nothing that happens in the script will affect the current shell.


[Jess in Action][AskingGoodQuestions]
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
thanks ernest...

can you please elaborate this more.....

i mean with some example...
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Well, if the script "myscript" contains just

export CLASSPATH=foo

Then if you run

% export CLASSPATH=bar
% . myscript
% echo $CLASSPATH

you'll see "foo" as the output. On the other hand, if you do

% export CLASSPATH=bar
% myscript
% echo $CLASSPATH

you'll see "bar".
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

The "source" function is used a lot for things like picking up configuration data for use by a calling script - especially in places like the /etc/init.d scripts in Red Hat/Fedora Linux where they designed the system to separate the updateable script code from the user/system-specific data.

By using a sourced script instead of a config file, the calling script is relieved of the need to parse the configuration definitions and assigne them to working variables - the shell does it.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: " . " used in front of shell scripts