title: How to pass a string argument to a command in a bash script?
body: <p>I concat all the arguments in a variable $ARGS and pass all of them to a command onece togather, just like what the <strong>./test_arg.sh</strong> do.</p>
  
  <p>But i found that the arguments with quoted string was splitted into multiple ones.</p>
  
  <p>Here is my test scripts, <strong>test_arg.sh</strong> perform the test case and <strong>arg.sh</strong> just print every argument on seperated line.</p>
  
  <pre><code>$ cat ./test_arg.sh 
  #!/bin/sh
  
  ARGS="$ARGS OPT_1"
  ARGS="$ARGS OPT_2"
  ARGS="$ARGS 'OPT_3 is a string with space'"
  
  echo "./arg.sh $ARGS"
  
  echo '----------------------------'
  
  ./arg.sh $ARGS
  [ xiafei@xiafeitekiMacBook-Pro ~/tmp ]
  $ cat ./arg.sh 
  #!/bin/sh
  
  for var in "$@"
  do
      echo "arg -&gt; $var"
  done
  </code></pre>
  
  <p>Here coms the result:</p>
  
  <pre><code>$ ./test_arg.sh
  ./arg.sh  OPT_1 OPT_2 'OPT_3 is a string with space'
  ----------------------------
  arg -&gt; OPT_1
  arg -&gt; OPT_2
  arg -&gt; 'OPT_3
  arg -&gt; is
  arg -&gt; a
  arg -&gt; string
  arg -&gt; with
  arg -&gt; space'
  </code></pre>
  
  <p>But if I put argument directly after the command it works correctly:</p>
  
  <pre><code>$ cat test_arg.sh 
  #!/bin/sh
  ./arg.sh OPT_1 OPT_2 'OPT_3 is a string with space'
  
  [ xiafei@xiafeitekiMacBook-Pro ~/tmp ]
  $ sh test_arg.sh 
  arg -&gt; OPT_1
  arg -&gt; OPT_2
  arg -&gt; OPT_3 is a string with space
  </code></pre>
  
  <p>I guess the problem is the way bash process quotes. Anyone knows about it?</p>