-1

Why does the values not get set in the array[@] and subsequently $i. This question has been asked before and I am aware of that , the reason I am asking here is because it doesn't work. Before you jump to mark this as duplicate, please can you let me know why it doesn't work? Not sure what is wrong here.

#!/bin/bash

DEALS=1739719, 1714630, 1733697, 1723940, 1666257, 1665239, 1674778, 1720875, 1674777, 1763086, 1735526, 1845881

IFS=', ' read -ra array <<< "$DEALS"

for i in ${array[@]}
do
        echo $i
done
serah
  • 2,057
  • 7
  • 36
  • 56
  • It doesn't work because your line `DEALS=1739719, 1714630, 1733697,...` isn't an assignment at all. It runs a *command* called `1714630,` with the first argument `1733697,` and the variable `DEALS=1739719,` temporarily set in the environment. – Charles Duffy Mar 14 '19 at 16:09
  • I need 2 more pairs of eyes ! – serah Mar 14 '19 at 16:10
  • Beyond that, `${array[@]}` has all the bugs of `${array[*]}`; it needs to be quoted, `"${array[@]}"`, to be accurate. Similarly, `echo $i` should be `echo "$i"` – Charles Duffy Mar 14 '19 at 16:10
  • ...anyhow, if you want to actually have `DEALS=...` be an assignment, quote the right-hand side. – Charles Duffy Mar 14 '19 at 16:11

1 Answers1

0

I failed to realise that I have to assign with quotes!

serah
  • 2,057
  • 7
  • 36
  • 56