title: bash: get only double dash or single dash options
body: <p>In a linux bash script, I want to have two lists of arguments: one are those started with single dash and the other those started with double dash. For example:</p>
  <pre><code>   script -a 1 --b=3 -c 7 --d=8
  </code></pre>
  <p>Then it can return them in two group variables:</p>
  <pre><code>  group1 : -a 1 -c 7
    group2 : --b=3 --d=8
  </code></pre>
  <p>I know that <code>$@</code> holds a list of all arguments. I don't know whether I should iterate them and make them distinct or there are easier solutions. This is my try:</p>
  <pre><code>g1=&quot;&quot;
  g2=&quot;&quot;
  for i in $@; do
     echo $i
     if [[ $i == --* ]]; then
        g1=&quot;${g1} $i&quot;
     else
        g2=&quot;${g2} $i&quot;
     fi 
  done
  echo $g1
  echo $g2
  </code></pre>
  <p>regardless of its accuracy, it says:</p>
  <pre><code>test.sh: 5: [[: not found
  </code></pre>