LAB 47: AUTOLOADING FUNCTIONS

 <  Day Day Up  >  

Steps for autoloading a function:

1. Make a directory called myfunctions .

2. Change directory to myfunctions and use the editor to create a file called good-bye .

3. Insert in the good-bye file a function called good-bye , spelled exactly the same as the filename.

4. The good-bye function contains:

 function good-bye { print The current time is $(date) print "The name of this script is 
 function good-bye { print The current time is $(date) print "The name of this script is $0" print See you later $1 print Your machine is ` uname “n` } 
" print See you later print Your machine is `uname n` }

5. Write and quit the editor. You now have a file containing a function with the same name.

6. Go to your home directory. Modify the . kshrc file in the editor by typing the following line:

 FPATH=$HOME/myfunctions 

7. Exit the editor, and to execute the .kshrc in the current environment, use the dot command.

8. In the timegreet script you wrote in Lab 45, include the following lines:

 autoload good-bye good-bye $LOGNAME 

9. Run the timegreet script. The good-bye function output will appear.

10. Create functions for each of the menu items in the lookup script. Store the functions in a file called lookup_functions in a directory called myfunctions .

11. Autoload the functions in your lookup script and make the function calls for the corresponding cases.

12. Use the trap command so that if the user enters a menu selection other than an integer value, the trap command will print an error to the screen, and cause the script to ask the user to re-enter the correct data type.

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net