Powered by Invision Power Board


  Reply to this topicStart new topicStart Poll

> Differences in script execution methods, Different behaviour in script execution
adamryardley
Posted: Jun 6 2005, 01:58 PM
Quote Post


Newbie
*

Group: Members
Posts: 3
Member No.: 638
Joined: 9-November 04



Hello - I need help understanding how the different methods for executing a script work?

As I understand it you can call/execute a script by running the following commands from the shell:
1) . scriptname
2) scriptname
3) bash scriptname

How are the 3 methods different and when should they be used?

As you can see I use the bash shell but I would be equally interested if there are any differences for the ksh shell.

Further to the above question (and here is the real reason why I've asked the above question) the different execution method produce different results when I use the $0 variable within my called script.
I would expect $0 to hold the name of the script being executed but when I use the ". scriptname" execution method $0 holds "bash".

Also I have a function which is declared in my .profile. I can execute it from the shell command line and can execute it from another script providing that script is called by the ". scriptname" apporach. But when running a script by means of methods 2) or 3) the script cannot see the function.
If it is because methods 2) and 3) create subshells to execute the script then why doesn't the subshell inherit all the environment variables and setting (including the function) from the parent shell?

The actual script I'm trying to execute fails for one of the two reasons depending on how I call it but the original author is no longer around to ask and I'm assured the script has worked correctly in the past.
Any help you can give will be greatly appreciated.

Many thanks

Adam
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | Shells & Scripting | Next Newest »

Topic Options Reply to this topicStart new topicStart Poll

 



[ Script Execution time: 0.1710 ]   [ 12 queries used ]   [ GZIP Enabled ]




Partners: Cambridge Plus :: <Link Available> :: USB Temperature Monitor :: <Link Available>
Unix Man Pages / Linux Man Pages :: HiFi Forum :: SIP VoIP Phone & Provider Reviews :: UNIX/Linux Forum Archives

More info on advertising on Unix/Linux Forum