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

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

2004


In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?

642


How do you know which shell I am using?

593


Where are cowrie shells found?

582


What is the equivalent of a file shortcut that we have a window on a linux system?

609






Explain how you Automate your application using Shell scripting.

1854


What is the syntax of "nested if statement" in shell scripting?

635


How to debug the problems encountered in the shell script/program?

632


Is shell scripting a programming language?

579


What is shell scripting?

595


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

576


Determine the output of the following command: [ -z “” ] && echo 0 || echo 1

560


What is scripting used for?

566


What exactly is a shell?

608


Is scripting and coding the same thing?

567