I want to print some logging style messages in my function, but also need to return a string value at the end of the function.
I came across namespaces but unfortunately I'm not working a recent enough version of bash.
For example:
doThing() {
echo "stuff"
echo "things"
echo "usefulstring"
}
result=$( doThing )
[[ $result = "usefulstring" ]] && echo "Worked" || echo "Failed. :("
I would really rather avoid globals, and from what I've read I should avoid eval. So what other options are there?
Also - I would like to see the logging echos on stdout, but not the return value. Is it possible to use redirection within the function to achive this?