I have an array of applications, initialized like this:
depends=$(cat ~/Depends.txt)
When I try to parse the list and copy it to a new array using,
for i in "${depends[@]}"; do
if [ $i #isn't installed ]; then
newDepends+=("$i")
fi
done
What happens is that only the first element of depends winds up on newDepends.
for i in "${newDepends[@]}"; do
echo $i
done
^^ This would output just one thing. So I'm trying to figure out why my for loop is is only moving the first element. The whole list is originally on depends, so it's not that, but I'm all out of ideas.
dependswill consist of 2 words,catand~/Depends, not the contents of~/Depends.txt.depends=$(cat ~/Depends.txt)the variabledependsis a scalar, not an array. Maybe you meantdepends=( $(cat ~/Depends.txt) )but that would be a bad way to try to populatedependsvsreadarrayorread -a.$(cat foo)would create a single element inxcontaining the entire contents of the filefoo, not an element per line of input as you'd get withreadarray. Add a second line tofoo, run each command to populatexand calldeclare -p xafter each to see the difference.