How to return a value from a bash function in a bash script

in «tip» by Michael Beard
Tags: , , , ,

Even though bash doesn't technically allow you to return a value (even through it has a return statement), there are ways you can accomplish this in the Return a value in a bash script says how, but I like tamasgal's answer best:

function fun1(){
  echo 34
}

function fun2(){
  local res=$(fun1)
  echo $res
}

I've used it to good affect in a couple of scripts, so I like what it does.