In the below bash I am trying to pass the ${array[$i]} to ssh after changing to a specific directory, but ${array[$i]} it is not recognized? The goal is to use the id in ${array[$i]} (there may be more than 1) to further go into that directory. The bash seems to work as expected except for the ${array[$i]} not be passed.
bash
readarray -t array <<< "$(printf '%s\n' $id)"
for ((i=0; i<${#array[@]}; i++ )) ; do
echo "${array[$i]}"
done
sshpass -f file.txt ssh -o strictHostKeyChecking=no -t xxx@xxx "${array[$i]}" 'cd path/to/folder/"$array[$i]" && exec bash -l'
echo ${array[$i]}
maybe?
readarray -t array <<< "$(printf '%s\n' $id)"
for ((i=0; i<${#array[@]}; i++ )) ; do
echo "${array[$i]}"
done
for i in "${array[$i]} ; do
sshpass -f file.txt ssh -o strictHostKeyChecking=no -t xxx@xxx "${array[$i]}" 'cd path/to/folder && exec bash -l'
done
contents of array[$i] ---- array[$i] will be different in number each time but the format will always be the same ----
00-0000-xxx-xxx-xxx
00-0001-yyy-yyy-yyy
desired ssh
cd path/to/folder/00-0000-xxx-xxx-xxx && cp *.txt* /home/location
cd path/to/folder/00-0000-yyy-yyy-yyy && cp *.txt* /home/location
printf '%s\n' "${array[@]}"is a much easier way to print all array contents one-line-to-an-item.sshpasscommand isn't in a loop at all, f/e; and when you pass multiple arguments to ssh, they're just concatenated together into a single shell command."${array[$i]}"as an extra argument: (1) what kind of thing do you expect it to contain? (2) how, and why, do you expect the remote shell to parse that opaque thing you aren't showing us in any particular way?