-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
4
  • 1
    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. Commented Mar 14, 2019 at 16:09
  • I need 2 more pairs of eyes ! Commented Mar 14, 2019 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" Commented Mar 14, 2019 at 16:10
  • ...anyhow, if you want to actually have DEALS=... be an assignment, quote the right-hand side. Commented Mar 14, 2019 at 16:11

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.