I am creating an array from the output of a command and then i am looping through the array and running commands that use each item in the array. Before i loop through the array i want to create a variable that uses one of the values in my array. I will use this value when one of the items in the array contains a specific string.
I am not sure how to pick the value i need to set the variable from my array before i then loop through the array. I currently have this which is not working for me. I have also tried looping through to get my value but the value does not follow to the next loop, i dont think its being set and i cant keep the loop open as i am looping inside my loop.
readarray -t ARRAY < <( command that gets array of 5 hostnames )
if [[ $ARRAY[@] == *"FT-01"* ]]; then
FTP="$ARRAY"
fi
for server in "${ARRAY[@]}"; do
echo "Server: ${srv}"
echo "-------------------"
if [[ $server == *"ER-01"* ]]; then
echo " FTP server is ${FTP} and this is ${server}"
fi
done
I'm pretty sure the first if statement would never work but i am at a loss to how to pick out the the value i need from the array.
srvbut uses$server. Please try to rephrase your question, fix and format your script, and maybe add a concrete example (something like "I have the array ..., because it contains ... I want to do ...").