• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

" . " used in front of shell scripts

 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks ernest...

can you please elaborate this more.....

i mean with some example...
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Saloon Keeper
Posts: 26541
187
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic