I'm using Dash because this is to run on my rPi. Bash is not an option.I'm rewriting a Bash script to work with Dash. I'm hoping to make it as POSIX-compliant (portable) as possible. The thing is it's difficult to find help on how to do loops through multi-line strings that don't involve Bash.My script works up until I reach a point where I have to go through a list of 100 to 1000 devices, each on their own line in a text file. For example, the file could look similar to:foobardeviceblahI'm importing the words using a simple cat command: LIST=$(cat $2). From here I need to loop through each word in $LIST:for ARRAY in ${LIST}do    printf Getting VLANS for: $ARRAY    VLANS=$(snmpbulkwalk -v 2c -t 2 -r 3 -c $COMMUNITY $ARRAY.dcs.byu.edu XIRRUS-MIB::vlanName -Oqv)    printf $ARRAY,$VLANS >> $REPORTdoneWhen the loop begins $ARRAY pretty much prints out everything that $LIST has, effectively making it pointless. It is vital that only one word is stored in $ARRAY since snmpbulkwalk can only handle one device at a time. It will return all data as one multi-line string, however this can be easily handled using sed to replace each newline with a comma.So, what is a proper and/or effective method of iterating through each word in a string? Arrays, from what I understand, are fairly non-existant in Dash, making mutations a little more difficult. I've tried using the Ubuntu guide and this very helpful reference. As I'm writing this I'm beginning to think that I may have to try to use grep to read line-by-line and nest another for-loop but I'm unsure if there's a more simple, clean way.You guys are fantastic! Quick, clean responses and some examples.So, I created two different versions of the script, both of which work perfectly. The first was done as roaima outlined and was also suggested by steeldriver. I replaced my loop with a while that would instead read my file line-by-line. Thank you for that, this certainly helps simplify things and shows that arrays were not necessary in my case.My second version simply replaced printf Getting VLANS for: $ARRAY with echo Getting VLANS for: $ARRAY and eventually I just removed it to see what would happen. Somehow this made all the difference: ARRAY did not contain everything that was in LIST which allowed the rest of the code to work properly. If someone wants to further clarify on how this worked please do so in the comments.Thanks again guys! It's working much faster than it did before on Bash. A few more tweaks to parse the data from snmp is all that's left!
I have a multi-line string that I need to iterate over, but I'm not using bash. Advice?
shell script;string;posix;dash
This is how I would read a line at a time from a filewhile IFS= read -r DEVICEdo    ....done < your_file