如何在 echo 中再次读取输入

如何在 echo 中再次读取输入

你好,我对 bash 脚本真的很陌生,

我试图制作一个脚本来检查服务器上的文件,所以我做到了,但它不会要求新的学生姓名,我如何告诉它再次读取我的输入?还如何告诉它从文件中获取服务器名称?

while read -p 'Enter the ip address for the server: ' ip_addr && [[ -z "$ip_addr" ]] ; do
 echo "No-no, please, no blank IP address!"
done

while [[ !  "$ip_addr" =~ ^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; do
    read -p "No-no not an valid IP. Re-enter: " ip_addr
done

while read -p 'Enter the student name: ' student_name && [[ -z "$student_name" ]] ; do
 echo "No-no, please, no blank student Name!"
done


while read -s -p 'Enter password: ' password && [[ -z "$password" ]] ; do
 echo "No-no, please, no blank passwords!"
done

y=$student_name
x=$y
####################################################################

sshpass -p "$password" ssh -o StrictHostKeyChecking=no $ip_addr "x=$y"  /bin/bash << "EOF"
                        sudo su - $x


ls -lrth ~/$USER/*DAT* | tail -10

pwd

ls -lrth ~/$USER/*PDF* | tail -10


##############################


while read -p 'Enter New student  Name: ' new_student _name && [[ -z "$new_student_name" ]] ; do
 echo "No-no, please, no blank student name!"
done

cat /opt/$USER/$new_student_name.txt

exit 0

fi

EOF

答案1

你在排队等候时忘记了一美元。

cat /opt/$USER/$new_student_name.txt

相关内容