Reputation:
I'm following the code mentioned here but it doesn't echo $result. Here is my code, I added quotations around the "$result". The echo in myfunc works, but the echo outside the function doesn't work. What is the problem? How do I fix it?
My Code:
#!/bin/bash
function myfunc()
{
local myresult="Hello World"
}
result=$(myfunc)
echo "$result"
Upvotes: 0
Views: 63
Reputation: 185025
#!/bin/bash
function myfunc()
{
local myresult="Hello World"
echo "$myresult" # the function need to return something
}
result=$(myfunc)
echo "$result"
Upvotes: 1