[root@foundation8 test]# cat if_complex.sh #!/bin/bash#looking for a possible valueif [ $USER = "student" ];thenecho"Welcome $USER"echo"Please enjoy your visiting!"elif [ $USER = "Bob" ];thenecho"Welcome $USER"echo"Please enjoy your visiting!"elif [ $USER = "Alice" ];thenecho"Welcome $USER"echo"Please enjoy your visiting!"elif [ $USER = "Coco" ];thenecho"Welcome $USER"echo"Please enjoy your visiting!"elseecho"Sorry,you're not allowed here."fi
[root@foundation8 test]# sh if_complex.sh
Sorry,you're not allowed here.
case闪亮登场
[root@foundation8 test]# cat case_better.sh #!/bin/bash#using the case commandcase$USERin
student|Bob|Alice|Coco)
echo"Welcome $USER"echo"Please enjoy your visiting!"
;;
*)
echo"Sorry,you're not allowed here."esac
[root@foundation8 test]# sh case_better.sh
Sorry,you're not allowed here.