-   Linux - Newbie (
-   -   Source or Execute an external Script from shell script (

helptonewbie 08-11-2010 12:31 PM

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...


echo $@

The thing is...

./ 123 456

123 456

I didn't realise the args of script would be passed to and able to be used in script

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

Thanks and Regards,

GrapefruiTgirl 08-11-2010 01:01 PM

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.

helptonewbie 08-11-2010 01:48 PM

Ahh course, should have known that really :-)

Thanks and great explaination!

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