fingolfin
fingolfin

Reputation: 19

How can I assign the output of a function with parameters to a variable using bash?

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.

Upvotes: 0

Views: 53

Answers (1)

vaughngx4
vaughngx4

Reputation: 198

@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 $?.

Upvotes: 2

Related Questions