Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-12-2010, 05:09 AM   #1
LQ Newbie
Registered: Apr 2009
Location: Maharashtra
Distribution: Fedora, FreeBSD
Posts: 5

Rep: Reputation: 0
Difference while executing script as . and ./


What is the difference when we execute a sh script like


Can any one please explain the difference?

Thanks in advance
Old 03-12-2010, 05:29 AM   #2
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 572

Rep: Reputation: 56
Let me address them in reverse order. The second syntax (./ tells your shell to look in the current directory for the script, and run it in a sub-shell. Any variables the script sets or changes are not available to the parent shell. This syntax is only needed if the current directory is not in the PATH. Otherwise you can just say and it will be found in the PATH and run. The ./ just means "look here, and nowhere else".

The second syntax (. - or even ". ./" if the script is in your current directory) is called "sourced". The script is run in the current shell, rather than a sub-shell and the variables it changes or creates are visible to the parent shell when the script terminates. I probably don't understand the full nuances of this approach, but I use it to set or change variables so they are available in the parent shell.

Last edited by blacky_5251; 03-12-2010 at 05:31 AM.
Old 03-12-2010, 05:59 AM   #3
LQ Newbie
Registered: Apr 2009
Location: Maharashtra
Distribution: Fedora, FreeBSD
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the answer. My concern was also about env variables not setting from script.

Old 03-12-2010, 07:27 AM   #4
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735Reputation: 735
I have seen "sourcing" most often as part of scripts. In a script, ". /path/somescript" means "make somescript part of the current script" (which, by definition, means run it in the same shell)

My concern was also about env variables not setting from script.
OK, what's the question?



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
shell script to find the difference betwwn two file and place the difference to other kittunot4u Linux - General 3 07-19-2010 04:26 AM
Run an external script, without holding up the currently executing script onesikgypo Programming 2 03-07-2009 09:26 PM
bash - difference between executing program in for loop and typing each command? jlarsen Programming 14 11-10-2008 05:38 PM
Difference between executing & sourcing a script muazfarooqaslam Linux - Newbie 1 01-04-2008 02:51 AM
Difference Executing In GUI And Konsole Shing Linux - Newbie 2 04-05-2005 11:19 AM

All times are GMT -5. The time now is 04:43 PM.

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