title: How to pass empty array as argument in bash
body: <p>I am trying to write a simple function in bash which takes 2 arguments, a string and an array.</p>
  
  <p>At the very beggining of the function I check for the number of arguments</p>
  
  <pre><code>function is2args() {
      if [ $# -le 1 ]; then
          return 1
      fi
  
      return 0
   }
  </code></pre>
  
  <p>I then attempt the following</p>
  
  <pre><code>arr=()
  is2args "" "${arr[@]}" # returns 1
  </code></pre>
  
  <p>This triggers the if statement as bash for some reason thinks there is only one argument however if the list is an empty string it works</p>
  
  <pre><code>arr=()
  is2args "" "" # returns 0
  </code></pre>
  
  <p>or filled with elements</p>
  
  <pre><code>arr=(
       "element"
  )
  is2args "" "${arr[@]}" # returns 0
  </code></pre>
  
  <p>and default to an empty string</p>
  
  <pre><code>arr=()
  is2args "" "${arr[@]:-""}" # returns 0
  </code></pre>
  
  <p>I don't quite understand what is going on. It is my understanding this is the correct way to pass a list however it seems that an empty list is ignored for whatever reason.</p>
  
  <p>Should I really be setting a default empty string every time I send through an array or is there a way to catch this in the function itself?</p>