How to declare functions in unix shell script?
Answers were Sorted based on User's Feedback
First method:
function function_name
{
}
Second Method:
function_name()
{
}
For both methods, the invocation of function would be in
the same format only.
Invocation:
function_name
| Is This Answer Correct ? | 62 Yes | 12 No |
Answer / prakash
function Dissplay () {
echo "This is how we define function"
}
Display # Invoking Function
## Function should be defined before we invoke it
| Is This Answer Correct ? | 67 Yes | 26 No |
Answer / nandish
we can pass the parameter also
ex: function fun_name () {
# write block here
}
invoke function as
fun_name parameter1 parameter2 ...
| Is This Answer Correct ? | 9 Yes | 3 No |
Answer / 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 |
What is a shell environment?
What language is used in terminal?
what is info area how many types?
Can shell script run on windows?
There are three departments A,B and C.Write a query to display the names of all the persons( in departments other than A) who are paid higher than the person receiving the lowest salary in DEPT A
What is the use of echo in shell script?
What are the different kinds of loops available in shell script?
What is scripting autism?
How will you print the login names of all users on a system?
What are the advantages of shell scripting?
What is eval in shell script?
what are bootlevel in linux?which level is booting by default.