在“输入服务器名称”并$servselect
在下面的脚本中设置变量后,在选择“Hello”和“Goodbye”选项后,该变量将丢失。这需要再次完成“输入服务器名称”提示。有没有办法在脚本完全退出之前维护该变量?任何建议将不胜感激。
#!/bin/bash
#
while true; do
read -p "Enter server name: " servselect
servselect=${servselect:-servselect}
echo $servselect has been selected!
printf '%s\n' \
"" \
"[A] Hello" \
"[B] Goodbye" \
"[Q] Quit" \
""
read -n1 -p 'Enter response here:' response
case $response in
[Aa]* )
printf '%s\n' \
"" \
"Hello, $servselect" \
""
;;
[Bb]* )
printf '%s\n' \
"" \
"Goodbye, $servselect" \
""
;;
[Qq]* )
printf '%s\n' \
"" \
"Quitting..." \
""
break
;;
* )
printf '%s\n' \
"" \
"Please choose A, B, or Q" \
""
;;
esac
done