![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing global variable to a function which is called by another function | sars | Shell Programming and Scripting | 4 | 06-30-2008 08:39 AM |
| Simple to you not simple to me pattern matchin help | aleks001 | Shell Programming and Scripting | 0 | 07-22-2007 07:06 PM |
| Simple C question... Hopefully it's simple | Xeed | High Level Programming | 6 | 12-15-2006 11:29 AM |
| Function within function (Recurance) | chassis | UNIX for Dummies Questions & Answers | 2 | 09-19-2006 06:32 AM |
| Ok simple question for simple knowledge... | Corrail | UNIX for Dummies Questions & Answers | 1 | 11-28-2005 10:03 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
hi all,
I am new to Shell Programming. I had a simple function here: function xyz { print "test" } I save the file as "abc" and give X to all. After I type abc from the terminal, I don't get the "test" as output. Am I missing anything? Thank you for your input in advance. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Is that all ther is to your shell script?
You have to "call" the function... #!/bin/ksh function xyz { print "test" } xyz exit 0 |
|
#3
|
|||
|
|||
|
Thanks rwb1959.
It works. I am reading the chapter about Shell Programming of "Learning the Korn Shell" from O'Reilly. I am trying out e.gs. However, they don't have the two lines: xyz exit 0 Although the problem is solved, I am wondering how come they would not have that. Is there any other way to "call" the function? I would appreciate it if you would let me know. |
|
#4
|
||||
|
||||
|
Typically, as in many "Learning" books, they are building
on past examples and it saves alot of paper if you don't keep printing the "whole" program/script over and over. So... you must call functions by name for them to be executed. Just FYI, the "exit 0" statement is not necessary. I just like including an exit code in case this shell script is executed by some other shell script or program. This way, you can determine the success or failure of the script by its' exit code. For instance... exit 0 - All is well exit 255 - Huston... we've had a problem The actual values are up to you but normally a "0" exit code says everything is AOK. |
||||
| Google The UNIX and Linux Forums |