Skip to main content
deleted 11 characters in body
Source Link
glarry
  • 974
  • 1
  • 7
  • 16

For example, in the snippet below, (how) is it possible to make array2 identical to array1 while still using a str variable?

~$ { str='a "b c" d'; array1=(a "b c" d); array2=( $str )
  for i in 0 1 2 3 4; do echo "${array1[$i]array1[1]}"; done${array1[2]}"
  for i in 0 1 2 3 4; do echo "${array2[$i]array2[1]}"; done;${array2[2]}"; }

b c d
"b c"

For example, in the snippet below, (how) is it possible to make array2 identical to array1 while still using a str variable?

~$ { str='a "b c" d'; array1=(a "b c" d); array2=( $str )
  for i in 0 1 2 3 4; do echo "${array1[$i]}"; done
  for i in 0 1 2 3 4; do echo "${array2[$i]}"; done; }

For example, in the snippet below, (how) is it possible to make array2 identical to array1 while still using a str variable?

~$ { str='a "b c" d'; array1=(a "b c" d); array2=( $str )
  echo "${array1[1]} ${array1[2]}"
  echo "${array2[1]} ${array2[2]}"; }

b c d
"b c"
deleted 25 characters in body
Source Link
glarry
  • 974
  • 1
  • 7
  • 16

For example, in the snippet below, (how) is it possible to make array2 identical to array1 while still using a str variable?

~$ { str='a "b c" d'; array1=(a "b c" d); array2=( $str )
  for i in 0 1 2 3 4; do echo "${array1[$i]}"; done
  for i in 0 1 2 3 4; do echo "${array2[$i]}"; done; }
 
~$ b c d
~$ "b c"

For example, in the snippet below, (how) is it possible to make array2 identical to array1 while still using a str variable?

~$ { str='a "b c" d'; array1=(a "b c" d); array2=( $str )
  for i in 0 1 2 3 4; do echo "${array1[$i]}"; done
  for i in 0 1 2 3 4; do echo "${array2[$i]}"; done; }
 
~$ b c d
~$ "b c"

For example, in the snippet below, (how) is it possible to make array2 identical to array1 while still using a str variable?

~$ { str='a "b c" d'; array1=(a "b c" d); array2=( $str )
  for i in 0 1 2 3 4; do echo "${array1[$i]}"; done
  for i in 0 1 2 3 4; do echo "${array2[$i]}"; done; }
Source Link
glarry
  • 974
  • 1
  • 7
  • 16

Why can't I convert a string variable into an array when some items include spaces?

For example, in the snippet below, (how) is it possible to make array2 identical to array1 while still using a str variable?

~$ { str='a "b c" d'; array1=(a "b c" d); array2=( $str )
  for i in 0 1 2 3 4; do echo "${array1[$i]}"; done
  for i in 0 1 2 3 4; do echo "${array2[$i]}"; done; }

~$ b c d
~$ "b c"