我编写了以下脚本来交互式输入服务器名称和服务名称。当 y 在 while 循环结束时作为输入给出时,这会重复询问输入。
key='y';
service='';
serverName='';
while [[ $key == 'y' ]]; do
echo -e "nEnter serverName : "
read serverName
echo -e "nEnter Service Name : "
read service
if [[ ! -z "$service" ] && [ ! -z "$serverName" ]]; then
echo -e "startService $serverName $service"
#echo -e " Atleast one input is null"
else
echo -e " Atleast one input is null"
fi
echo -e "Enter y to repeat this step. Enter n to exit :"
read key
done
您的while循环条件是错误的,请像下面这样更正:-
while [[ '$key' == 'y' ]];
或
while [[ $key == y ]];