I've been trying to take the output of ls /Applications/ and put each line into an array, then do a for loop of the array.
#!/bin/bash
ls /Applications | grep Adobe > adobeapps
adobearray=( 'cat "adobeapps" ')
for i in "${adobearray[@]}"
do
codeigottadowith $i
done
exit
It doesn't work, and I found that even when I try to just declare a simple array with:
declare -a adobearray=(item1 item2 item3); echo $adobearray[1];
The output is item1[1]. It takes the first element and makes that the whole array. Why is this wrong? What dumb thing am I doing? And is there a better way in bash to send the output of ls to an array?
Thanks for your help!
echo $arraynameonly prints the first element, soecho $arrayname[1]is just printing the expansion of$arrayname, followed by printing the literal sequence[1]; it's not actually expressing to you that the first element "is the whole array" in any meaningful respect.declare -p arrayname. Works for any other shell variable too.