title: return a value from shell script, into another shell script
body: <p>I know how to return an exit code, but I would like to return the result of an operation done in a shell script function, so I can eventually use it in another script or function.</p>
  
  <p>Something like </p>
  
  <pre><code>var1=$(myfunction)
  
  function2 var1
  </code></pre>
  
  <p>Where myfunction could be something like A+B=C</p>
  
  <p>I looked into "return", but it will return a code, not a value.</p>
  
  <p>I am looking into various sites that show how to write functions, but I don't see how you actually return values.</p>
  
  <p>In C++ you would use return "variable name", but shell script won't allow this. It says that the variable do not exist (which is logical, it is a variable created in a function, so when the function is released, that memory space assigned to it is gone). Can't use global variables since the function may be in one script and the calling function that needs the return value, may be in a different one.</p>