title: bash command grouping for test results in function
body: <p>I am accustomed to testing that a variable has a non-null value (or give a message and bail) using a line like this:</p>
  
  <pre><code>test $variable || (echo "Value of \$variable cannot be null."; exit 1)
  </code></pre>
  
  <p>I'm quite new to using functions in my scripts, but I've got a case where I need to be sure a non-null value is passed or bail out of the function.  However the command grouping for the "or" case is not working the same way inside the function.  I wrote this little test script to demonstrate:</p>
  
  <pre><code> $ cat -n bubu.sh
   1  #!/bin/bash
   2
   3  read -p "give a value for variable \$foo: " -e -i "bar" foo
   4
   5  function firstfunc {
   6          test $1 || (echo "no value"; return 1)
   7          echo it looks like \"$1\" is  the first value of \$foo
   8          return 0
   9  }
  10
  11  function secondfunc {
  12          test $1 || return 1
  13          echo it looks like \"$1\" is the second value of \$foo
  14          return 0
  15  }
  16  echo "first function:"
  17  firstfunc $foo
  18  echo returned $?
  19
  20  echo "second function:"
  21  secondfunc $foo
  22  echo returned $?
  </code></pre>
  
  <p>And the output in the case where the variable <strong>has</strong> a value is like this:</p>
  
  <pre><code>$ ./bubu.sh
  give a value for variable $foo: bar
  first function:
  it looks like "bar" is the first value of $foo
  returned 0
  second function:
  it looks like "bar" is the second value of $foo
  returned 0
  </code></pre>
  
  <p>And the output in the case where there <strong>is not</strong> a value</p>
  
  <pre><code>$ ./bubu.sh
  give a value for variable $foo:
  first function:
  no value
  it looks like "" is the first value of $foo
  returned 0
  second function:
  returned 1
  </code></pre>
  
  <p>In the first function when there is not a value I get the first command of the "or" command group, and "no value" echoes, but the return command is passed by and the rest of the function is executed, down to the return.</p>
  
  <p>Why are the parens for command grouping behaving differently inside the function, or what else am I missing?</p>