LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 08-11-2010, 12:31 PM   #1
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
Smile Source or Execute an external Script from shell script


Hi All,

I know this is a simple to answer one... but its hard to search google for source'ing or executing a script with '. script'.

Basically, i've realised it seems possible to have one script...
test.sh
Code:
#!/bin/bash
. test1.sh
test1.sh
Code:
#!/bin/bash
echo $@
The thing is...
Code:
./test.sh 123 456

Output:-
123 456
I didn't realise the args of script test.sh would be passed to and able to be used in script test1.sh

Just wondering why this happens more than anything? Its not a problem or anything really... just interested.

Thanks and Regards,
M
 
Old 08-11-2010, 01:01 PM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
When you source a script, rather than call it explicitly, it inherits the environment of the script which sourced it. Therefore, the parameters passed to the original script initially, are available to the sourced code. When you source a second script into a first one, it acts as though the sourced code is part of the original script, i.e. it acts as though it were all one script.
 
Old 08-11-2010, 01:48 PM   #3
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
Ahh course, should have known that really :-)

Thanks and great explaination!
 
  


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
how to execute Source command in a shell script UltraSoul Linux - General 3 09-23-2010 11:13 AM
How can i execute shell script from firefox? solo9300 Linux - General 3 09-30-2009 11:13 AM
help with execute mulitple shell script within shell script ufmale Programming 6 09-13-2008 01:21 AM
shell script won't execute brandnewbie Linux - Newbie 7 08-10-2004 02:30 PM
shell script how to execute x2000koh Programming 6 07-29-2003 05:20 PM


All times are GMT -5. The time now is 06:20 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration