思路:while 死循環加if判斷語句30秒判斷一次用戶登陸信息 #!/bin/bash read -p "please input a username : " user while : do if who |grep -qw "$user" ;then #grep -q 不顯示輸出信息 -w 精確查找 echo "$user is login!" exit#退出循環 else echo -e "$user does not exist!\nMonitoring..." fi sleep 30#睡眠30秒 done