I am trying to make a script to get ip list from file and show it on screen with select option, and make ssh to that IP just by selecting. File is like below;
name1 1.1.1.1
name2 2.2.2.2
name3 3.3.3.3
name4 4.4.4.4
Below script can read the list from file and shows it on screen as menu.It show both name and IPs for selection, but I want to show selection menu just by name. How can I achieve this?
PS3='Please enter your choice: '
readarray -t options < ./file.txt
select opt in "${options[@]}"
do
IFS=' ' read name ip <<< $opt
case $opt in
$opt) ssh $ip;;
esac
done
1) name1 1.1.1.1
2) name2 2.2.2.2
3) name3 3.3.3.3
4) name4 4.4.4.4
Please enter your choice: 1