I have created an array (3 elements), and each element contains a comma delimited string. The array was created by reading a file line by line - the file contains fields output from a database. I have written the code below in order to iterate through each string element, as though it were too an array.
It works, apart from one strange error, the last element in the array has an additional @ symbol
(also declare -A didn't work, though I've made sure I'm using bash 4 on my mac)
i=0 declare -a items while read line do items[i]=$line ((i++)) done < test_file1.txt declare -a item_arr for item in "${items[@]}" do item_arr=($item[@]) done echo "${item_arr[4]}://${item_arr[1]}:${item_arr[3]}@${item_arr[2]}/control/configinfo"
output is: https[@]://192.168.1.152:username@pwd/control/configinfo
Why is the @ symbol printing out? Am I wasting my time, should i have used awk instead? otherwise, it feels like a fairly straightforward way, but that could be as I'm relatively inexperienced. Potentially the most items I may need to initialise in this would be 1 to 200.
The purpose of my code is to create a curl request to obtain some config_info, the user name, password, ip address, protocol are all pulled from a database in order to build a curl request for each item.
thanks in advance!