The below code snippet shows how to pass the parameters to the function in shell script. If we used $1,$2,,,$n with in the function
$1 says first argument of this function
$2 says second argument of this function
.
.
.
$n says nTh argument of this function.
#!/bin/bash
add()
{
x=$1;
y=$2;
z=`expr $x + $y`;
echo $z
}
sum=`add 10 20`
echo "sum x=10 y=20 x+y=$sum"
OUTPUT:
-bash-3.2$ sh passing_parameter_mech
sum x=10 y=20 x+y=30
sum=`add 10 20`
calling the function add with passed two parameters 10 and 20 and return value is assigned into variable sum here need to put it both side of function call `(tilde) sign.
x=$1
values of 10 is assigned into the variable x
y=$2
values of 20 is assigned into the variable y
we can call x and y as dereferenced variables in shell function.
A Language is not worth knowing unless it teaches you to think differently.
Subscribe to:
Post Comments (Atom)
Item - Category Query
SELECT msi.segment1 AS Item_Code, msi.DESCRIPTION AS Item_Desc, mcs.CATEGORY_SET_NAME, mck.CONCATENATED_SEGMEN...
-
1. To download Ldt file for a Concurent Program FNDLOAD [username]/[password] O Y DOWNLOAD $FND_TOP/patch/115/import/afcpprog.lct file_nam...
-
The profile information available in the HZ_CUSTOMER_PROFILES can be created in three levels namely Party, Customer Account and Customer...
-
Here the article will describe about how to register WebADI to Responsibility menu Go to System Administrator --> Security --> Respo...
No comments:
Post a Comment