How to declare functions in unix shell script?

Answer Posted / pitambar mishra

### Note : Function always returns a value.
### This script is for adding two numbers.
### Script name : add.ksh

#!/bin/ksh

sum() ### Defining sum function
{
echo enter 2 no :
read num1 num2
echo sum=$(( num1 + num2 ))
}
sum ### Invoking sum function

To execute it :
ksh add.ksh

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is mac default shell?

790


What is an inode block?

780


How to redirect both standard output and standard error to the same location?

885


How will you find the 99th line of a file using only tail and head command?

2243


How to print all the arguments provided to the script?

749


What is a shell script in windows?

759


What are script files?

719


Rewrite the command to print the sentence and convert the variable to plural: echo “i like $variable”.

798


What does chmod do?

750


What is eval in shell script?

875


What is the crontab?

727


What is shell scripting used for?

743


How to pass an argument to a script?

766


What is the meaning of $1 in shell script?

805


Please give me example of " at command , contrab command " how to use

2520