while true; do clear for index in "${!choices[@]}"; do if [ $index -eq $selected ]; then printf "\033[31m> ${choices[$index]}\033[0m\n" # 高亮显示选中的选项 else echo " ${choices[$index]}" fi done
read -n1 -s key # 读取单个按键并保持输入的隐私
case "$key" in A) # 上箭头 if [ $selected -gt 0 ]; then selected=$((selected - 1)) fi ;; B) # 下箭头 if [ $selected -lt $(( ${#choices[@]} - 1 )) ]; then selected=$((selected + 1)) fi ;; "") # 回车键 break ;; esac done # 打印最终结果日志 selected_option="${choices[$selected]}" echo "最终选择:$selected_option" }
isReadlink=$(readlink $0 | wc -l)
if [ $isReadlink == "0" ] then echo -e "\e[31m警告: $0只能是1个软连接\e[0m" exit 999 fi
apt install -y sshpass > /dev/null 2>&1
sshFile=$(readlink $0 | sed "s@link-to-ssh.sh@link-to-ssh.csv@g")
if [ $( ls $sshFile | wc -l) == "0" ] then echo -e "\e[31m警告: link-to-ssh.sh和link-to-ssh.csv不在同一目录\e[0m" exit 999 fi
options=() index=0 for line in `iconv -f GBK -t UTF-8 $sshFile | grep -v name` do info=$(echo $line | awk -F ',' '{print $1}') options[$index]=$info index=$((index+1)) done