| UNIX/Linux Forum Archives · Rules and Guidelines · Disclaimer |
Help
Search
Members
Calendar
|
| Welcome Guest ( Log In | Register ) | Resend Validation Email |
![]() ![]() ![]() |
| adamryardley |
Posted: Jun 6 2005, 01:58 PM
|
|
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 |
![]() |
![]() ![]() ![]() |