LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 02-10-2015, 11:24 AM   #1
Upendra Pratap Singh
Member
 
Registered: May 2011
Location: India
Distribution: Ubuntu 14.04
Posts: 110
Blog Entries: 4

Rep: Reputation: 0
benefit of source command


Hi,

What are the benefits that we get when we choose to source a file rather than execute it as a shell script?

and then in what way is export opposite to source?

It looks like they are doing the same thing, i.e making environment variables accessible in the local shell
 
Old 02-10-2015, 12:59 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,475
Blog Entries: 10

Rep: Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639Reputation: 1639
Executing it as a shell script is using the source command because source is abbreviated with the DOT. It's really that simple, DOT is source, and vice-versa.

http://en.wikipedia.org/wiki/Source_%28command%29

Or see the first answer, not the comments, the answer http://superuser.com/questions/46139...does-source-do where they say:
Quote:
source is a bash shell built-in command that executes the content of the file passed as argument, in the current shell. It has a synonym in '.' (period).

Last edited by rtmistler; 02-10-2015 at 01:01 PM.
 
Old 02-10-2015, 03:56 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by Upendra Pratap Singh View Post
Hi,

What are the benefits that we get when we choose to source a file rather than execute it as a shell script?
Primarily, this is used so that modifications to the environment (such as PATH) that are made in the script will be usable by the shell in the future.
Quote:
and then in what way is export opposite to source?
One problem with including scripts this way is that the shell environment starts getting lots of variables that don't make any sense. This is the advantage a separate process has - its environment is isolated from the parent (initially copied, but any changes made will not affect the parent), and the environment is automatically cleaned up when the process exits.
Quote:

It looks like they are doing the same thing, i.e making environment variables accessible in the local shell
Only when the script is included will the variables be available to the shell. When run as a new process, it is separate.
 
  


Reply


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
LXer: Small firms can benefit from open source LXer Syndicated Linux News 0 03-06-2009 04:50 PM
LXer: Will Open Source Benefit From New Business Intelligence Boom? LXer Syndicated Linux News 0 03-06-2009 06:10 AM
Is there any open source project benefit from professional testing? bdaedalus359 General 1 01-20-2009 04:45 PM
LXer: Three Ways That Open Source Could Benefit from Business 101 LXer Syndicated Linux News 0 08-28-2008 03:10 AM
LXer: How Open Source Could Benefit Elections LXer Syndicated Linux News 0 07-23-2007 12:31 PM


All times are GMT -5. The time now is 03:42 PM.

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