simple function

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers simple function
# 1  
Question simple function

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.
# 2  
Is that all ther is to your shell script?

You have to "call" the function...


function xyz {
print "test"


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 However, they don't have the two lines:

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. Smilie

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #1003
Difficulty: Medium
In the 1970s, Grace Hopper, also known as "Grandma COBOL", pushed for the Defense Department to replace large, centralized systems with networks of small, distributed computers.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies

2. UNIX for Beginners Questions & Answers

Simple shell script function

Hello, Trying to look vgcheck() { lsvg -o| while read vg; do lsvg -p $vg|grep Missing if ;then echo "OK:PASSED" else echo "FAIL" ... (3 Replies)
Discussion started by: kvosu
3 Replies

3. Shell Programming and Scripting

Wrong test interpretation for simple function.

Hello everyone, I have written simple script below to check if ip is added to interface #!/usr/local/bin/bash IFCONFIG="/sbin/ifconfig" SERVICE="/usr/sbin/service" IP="79.137.X.X" GREP=$(${IFCONFIG} | grep ${IP}) ip_quantity_check () { echo ${GREP} | wc -l } if ];... (2 Replies)
Discussion started by: bryn1u
2 Replies

4. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

5. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

6. Shell Programming and Scripting

Help with a simple function

Hi there Everytime it calls the second if statement it keeps calling the first echo message from the first if statement. how do I get it to display the second echo message in the second if statement? Thanks. function (verbose) { if ; then echo "rm: cannot remove $1 : is a... (8 Replies)
Discussion started by: bob21
8 Replies

7. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

8. Shell Programming and Scripting

Simple Shell Script using function

Hi all, I am new to shell scripting.I have made a simple shell script which will give me number of records in a database table. The SQL statement is working fine and there are 11 rows in this table. But problem is that it is not printing this value and fucntion does not get called. Please see the... (5 Replies)
Discussion started by: 33junaid
5 Replies

9. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies