title: $@ puts all Command line input in a single array element in Bash
body: <p>I am new to Bash Scripting and was working with arrays when the <a href="https://www.javatpoint.com/bash-variables" rel="nofollow noreferrer">tutorial</a> I was referring to stated that command line arguments could be turned to an array using &quot;$@&quot; so i wrote a simple script that would input two command line arguments into an array and print them</p>
  <pre><code>script1.sh
  #!/bin/bash
  array=(&quot;$@&quot;)
  echo &quot;whole array : $@&quot;
  echo &quot;arr[0]: ${array[0]}&quot;
  echo &quot;arr[1]: ${array[1]}&quot;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/7NtiD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7NtiD.png" alt="enter image description here" /></a></p>
  <p>but when i run it as</p>
  <pre><code>./script1.sh hello world
  </code></pre>
  <p>it gives output as</p>
  <p><a href="https://i.stack.imgur.com/J5q7I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J5q7I.png" alt="enter image description here" /></a></p>
  <p>it puts all arguments in array[0], i do not understand..
  some stack overflow articles comes close to this issue
  I am using Kali Linux Downloaded from windows store with Windows Subsystem for linux turned on , if that should be of any help.....</p>
  <p><strong>EDIT :</strong></p>
  <p>I created a small <strong>GIF</strong> and uploaded it publicly on gifyu to show the execution and prove that i used the same code!
  link : <a href="https://gifyu.com/image/eqvT" rel="nofollow noreferrer">https://gifyu.com/image/eqvT</a></p>
  <p>added $BASH_VERSION as a user pointed out in comments...</p>
  <p><strong>EDIT 2:</strong></p>
  <p>output of <strong>locale</strong></p>
  <p><a href="https://i.stack.imgur.com/ENI4x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ENI4x.png" alt="enter image description here" /></a></p>
  <p><strong>DEBUG</strong></p>
  <p><a href="https://i.stack.imgur.com/Mjt6a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mjt6a.png" alt="enter image description here" /></a></p>
  <p><strong>EDIT 3:</strong>
  I am Finally able to Run the Script as desired by using</p>
  <pre><code>#!/bin/bash
  echo Bash Version: $BASH_VERSION
  str=&quot;$@&quot;
  read -r -a array &lt;&lt;&lt; &quot;$str&quot;
  echo &quot;array[0]:&quot; ${array[0]}
  echo &quot;array[1]:&quot; ${array[1]}
  echo &quot;array[2]:&quot; ${array[2]}
  </code></pre>
  <p>But it would be helpful if i knew why $@ was not working....</p>
  <p>and also the <a href="https://mywiki.wooledge.org/WordSplitting" rel="nofollow noreferrer">automatic Word Splitting</a> doesn't work
  for example if I change the code to</p>
  <pre><code>str=&quot;$@&quot;
  array=( $str )
  </code></pre>
  <p>then output is given as</p>
  <p><a href="https://i.stack.imgur.com/x9GCk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x9GCk.png" alt="enter image description here" /></a></p>
  <p><strong>EDIT 4:</strong>
  Well it works flawlessly on Ubuntu 20.04 LTS</p>
  <p><a href="https://i.stack.imgur.com/8o8UF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8o8UF.jpg" alt="enter image description here" /></a></p>
  <p>Output :</p>
  <p><a href="https://i.stack.imgur.com/Uy1zw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uy1zw.jpg" alt="enter image description here" /></a></p>
  <p>I think there is some problem with kali WSL OR my there is some environmental or Configuration problem in my PC.</p>