example (){
......
local var
......
return $var
}
user_val=$(example $number1 $number2)
I need user_val and i will it. I got error. Code can't detect the function when I try it this way.
@Barmar is correct. Replace return with echo in your function. Using var=$(...) assigns the output of the function to the variable.
When using return the value is saved in $?.
$? is a an 8-bit integer (byte).
user_val= example $number1 $number2I tried it but can not assign$()captures the output of the command, not the return value. Changereturntoecho.example "$number1" "$number2"; user_val="$?"; echo "$user_val"