title: shell script function return a string
body: <p>I am new to shell scripts, I am trying to create a simple function which will return the concatenated two strings that are passed as parameters. I tried with below code</p>
  
  <pre><code>   function getConcatenatedString() {
         echo "String1 $1"
         echo "String2 $2"
         str=$1/$2
         echo "Concatenated String ${str}"
         echo "${str}"
     }
  </code></pre>
  
  <p>//I am calling the above function</p>
  
  <pre><code>  constr=$(getConcatenatedString "hello" "world")
    echo "printing result"
    echo "${constr}"
    echo "exit"
  </code></pre>
  
  <p>I see the below output when running the script with above code,</p>
  
  <pre><code>   printing result
     String1 hello
     String2 world
     Concatenated String hello/world
     hello/world
     exit
  </code></pre>
  
  <p>If you look at the code I am first calling the function and then I am echoing "printing result" statement, but the result is  first comes the "printing result" and echos the statement inside the function. Is the below statement calling the function </p>
  
  <pre><code>   constr=$(getConcatenatedString "hello" "world")
  </code></pre>
  
  <p>or</p>
  
  <pre><code>   echo ${constr}
  </code></pre>
  
  <p>is calling the function ?</p>
  
  <p>Because if I comment out #echo ${constr} then nothing is getting echoed !!! Please clarify me.</p>