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 shell scripting?
Write a shell script to looking at the log file to see if the test has passed or not
What will happen to my current process when I execute a command using exec?
if i have 2 files file1 and file2.... file1 contains 2 columns like b a 11 aa 12 as 13 ad 15 ag 11 ar 13 ah 15 ak file2 contains b c 10 ds 11 at 15 gh 15 jk 13 iu 11 fg 13 yy can any 1 give me the program to display in this way? a b c aa 11 at ar 11 fg ad 13 iu ah 13 yy ag 15 gh ak 15 jk
How do I run a bin bash script?
State the advantages of shell scripting?
What is a shell in operating system?
What is the difference between a 'thread' and a 'process'?
How do scripts work?
How do you rename the files(*.sh) with file names containing space in it?for example "interview question.sh" needs to rename to "interview-question.sh". Appreciate your inputs.Thanks.
how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com
Is shell script a programming language?