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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-12-2010, 05:09 AM
|
#1
|
|
LQ Newbie
Registered: Apr 2009
Location: Maharashtra
Distribution: Fedora, FreeBSD
Posts: 5
Rep:
|
Difference while executing script as . and ./
Hi
What is the difference when we execute a sh script like
and
Can any one please explain the difference?
Thanks in advance
|
|
|
|
03-12-2010, 05:29 AM
|
#2
|
|
Member
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569
Rep:
|
Let me address them in reverse order. The second syntax (./script.sh) 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 script.sh and it will be found in the PATH and run. The ./ just means "look here, and nowhere else".
The second syntax (. script.sh - or even ". ./script.sh" 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.
|
|
|
|
03-12-2010, 05:59 AM
|
#3
|
|
LQ Newbie
Registered: Apr 2009
Location: Maharashtra
Distribution: Fedora, FreeBSD
Posts: 5
Original Poster
Rep:
|
Thanks for the answer. My concern was also about env variables not setting from script.
Thanks
|
|
|
|
03-12-2010, 07:27 AM
|
#4
|
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,797
|
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)
Quote:
|
My concern was also about env variables not setting from script.
|
OK, what's the question?
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:20 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|