Shell Scripting - Function
|
Original Message
|
Name: pmjain
Date: February 20, 2004 at 22:53:13 Pacific
Subject: Shell Scripting - Function OS: UNIX- Windows CPU/Ram: -----
|
Comment: Hi Can u please let me know how can i have all the functions in one shell script and then later call these functions in another script. for eg i want to create a shell script which will consist of the functions which will 1st function to log the start time , 2nd function to log the completion time 3rd function to log the the total time required for exectuion of the script. These functions will be called in another script so can u let me know how can i have all the functions in one script and then how can i call each one of them as required in another script. regards Shalini
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: aigles
Date: February 21, 2004 at 05:55:37 Pacific
Subject: Shell Scripting - Function
|
Reply: (edit)Put all yours functions in one file 'functions.sh' for example. --- function.sh --- start_time() { . . . } completion_time() { . . . } . . . ------------------- In your main script, source the functions file :
--- Main script --- # source functions definitions . functions.sh # now all functions are available
------------------- Jean-Pierre.
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: nails
Date: February 21, 2004 at 09:30:08 Pacific
Subject: Shell Scripting - Function |
Reply: (edit)Hi: Check out this link: http://www.computing.net/unix/wwwboard/forum/5877.html for additional information on declaring functions. Regards, Nails
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: pmjain
Date: February 23, 2004 at 08:52:34 Pacific
Subject: Shell Scripting - Function
|
Reply: (edit)Thanks a lot for ur responses those have really helped me a newbie in this world of shell scripting i would like to know after sourcing the functions to the main script can i call the functions just by the name functions.sh has a function s_interval eg main_script.sh is as follows functions.sh echo "functions called" s_interval will this suffice or do i need to use any other way of calling the s_interval function i have to also find the total execution time of the script is it possible to take the start time and the completion time and then subtract the start time from the completion time. can anyone of u help me in doing this or atleast providing a hint. can i do it this way, let me know if its correct. start_time() { date+%H%M%S } end_time() { date+%H%M%S } s_interval() { arg1=start_time() arg2=end_time() arg3=expr arg2-arg1 } thanks in advance Shalini
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: