=========================DEMO1==========================
#!/bin/bash read -p "Please input your number:" num read -p "Please input your password:" -t 5 passwd echo 账号: $num 密码: $passwd
=========================DEMO2==========================
#!/bin/bash echo -n "\$0: " echo "Program name is $0" echo -n "\$#: " echo "There are totally $# parameters" echo -n "\$*: " echo "The parameters is: $*" echo -n "\$\$: " echo "The program's pid is $$" echo -n "\$?: " echo "The program result is $?"
=========================DEMO3==========================
#!/bin/bash function login(){ echo -n "Login : " read name stty -echo ###### doesn't show what you input echo -n "Password : " read passwd stty echo errcount=$((errcount+1)) judge } function judge(){ ##if [ $name = "zhang" -a $passwd = "618" ];then tmpnp=$name$passwd awk '{print $1$2}' /zhang/shell/testfile/users | grep $tmpnp if [ $? = 0 ];then echo "Login success!" elif [ $errcount -eq 3 ] ;then echo "You have tried 3 times!" exit else /usr/bin/clear echo "Your have `expr 3 - $errcount` times changes!" login fi } errcount=0 login
=========================DEMO4==========================
#!/bin/bash ### FUNCTION : case echo -n 'Enter [Y|N]:' read tmp case $tmp in y|yes|Y|YES) echo "You enter is $tmp" ;; n|no|N|NO) echo "You enter is $tmp" ;; *) echo "erro" ;; esac
=========================DEMO5==========================
#!/bin/bash factorial=1 for num in `seq 1 10` do factorial=`expr $factorial \* $num` done echo "10! = $factorial"
=========================DEMO6==========================
#! /bin/sh while true do echo "*******************************" echo "Please select your operation:" echo " 1 Copy" echo " 2 Delete" echo " 3 Backup" echo " 4 Quit" echo "*******************************" read op case $op in C|c) echo "your selection is Copy" ;; D|d) echo "your selection is Delete" ;; B|b) echo "your selection is Backup" ;; Q|q) echo "Exit ..." break ;; *) echo "invalid selection,please try again" esac done
转载于:https://blog.51cto.com/nicemove/1387337