标签:
[root@Salve]# cat demo.sh #!/bin/bash read -p "enter you name:" name echo "my name is $name" [root@Salve]#./demo.sh enter you name:Tom my name is Tom
[root@Salve]# cat demo.sh #!/bin/bash read -p "enter you name:" name echo ‘my name is $name‘ [root@Salve]# sh demo.sh enter you name:user44 my name is $name
[root@Salve]# cat demo.sh #!/bin/bash read -p "enter you name:" name echo ‘my name is‘ $name [root@Salve]#./demo.sh enter you name:user55 my name is user55
[root@Salve]# cat demo.sh #!/bin/bash read -p "enter you name:" name echo ‘$name /n $name /n $name‘ echo "$name /n $name /n $name" [root@Salve]# sh demo.sh enter you name:user $name /n $name /n $name user /n user /n user
[root@Salve scripts]# cat test.sh #!/bin/bash str1=`echo 123` str2=`date` echo $str1; echo "today is: $str2"; echo "today is: $str2!!!"; [root@Salve scripts]#./test.sh 123 today is:2016年05月24日星期二21:30:17 CST today is: 2016年 05月 24日 星期二 21:30:17 CST!!!
[root@Salve]# cat test.sh #!/bin/bash #test.sh name=‘user123‘ echo $name unset name echo $name [root@Salve]# sh test.sh user123
[root@Salve scripts]# cat demo.sh #!/bin/bash echo $1 echo $2 echo $3 echo $4 echo $5 echo $6 echo $7 echo $8 echo $9 echo $10 [root@Salve scripts]#./demo.sh a b c d e f g h i j a b c d e f g h i a0
例子:
[root@Salve scripts]# cat demo.sh #!/bin/bash case $1 in start) echo ‘start...‘ ;; stop) echo ‘stop...‘ ;; esac [root@Salve scripts]#./demo.sh start start... [root@Salve scripts]#./demo.sh stop stop...
[root@Salve scripts]# cat a.sh #!/bin/bash echo "当前您正在执行的脚本名称是:"$0 echo $0 echo $0
[root@Salve scripts]#./a.sh
当前您正在执行的脚本名称是:./a.sh
./a.sh
./a.sh
[root@Salve scripts]# cat a.sh #!/bin/bash echo "总共有${#}个参数" echo "参数的内容是:$*" [root@Salve scripts]#./a.sh a b c d e f g h i j k l m n o p q 总共有17个参数 参数的内容是:a b c d e f g h i j k l m n o p q
例子C:
[root@Salve scripts]# cat b.sh #!/bin/bash for i in$*;do echo $i done [root@Salve scripts]#./b.sh a b c a b c
[root@Salve scripts]# cat test.sh #!/bin/bash tot=0 for i in $*;do tot=$(($tot+$i)) done echo $tot [root@Salve scripts]#./test.sh 12345 15
[root@Salve scripts]# cat temp.sh #!/bin/bash ls -l echo $? [root@Salve scripts]#./temp.sh 总用量8 -rwxr-xr-x.1 root root 285月2414:31 temp.sh -rwxr-xr-x.1 root root 695月2414:27 test.sh 0
[root@Salve scripts]# cat temp.sh #!/bin/bash #ll ls if[[$?==0]];then echo ‘上一条命令执行成功‘ else echo ‘上一条命令执行失败‘ fi [root@Salve scripts]#./temp.sh temp.sh test.sh
上一条命令执行成功
[root@Salve scripts]# cat a.sh #!/bin/bash expr 10+20 expr $1 + $2 num=`expr 1+2` echo $num [root@Salve scripts]#./a.sh 1155 30 66 3
[root@Salve scripts]# cat a.sh #!/bin/bash num1=$((4+2)) num2=$((4-2)) num3=$((4*2)) num4=$((4/2)) num5=$((4%2)) echo $num1 echo $num2 echo $num3 echo $num4 echo $num5 [root@Salve scripts]#./a.sh 6 2 8 2 0
标签:
原文地址:http://www.cnblogs.com/chinas/p/5557741.html