it's my first question. I just want to know how could I save the result of the function 'square' into the variable 'sqr':
!/bin/bash
function square()
{
let y=$x*$x
return $y
}
x=3
**sqr=square**
echo "The square of $x is $sqr"
The functions in bash are really procedures (it does not return anything). Therefore you have two options: Save in a goblal variable the result, or save the output:
function myfunc(){
myresult='anything'
}
myfunc
echo $myresult
or
function myfunc(){
local myresult='anything'
echo "$myresult"
}
result=$(myfunc)
echo $result