shell命令行参数
-bash-4.2$ cat test1.sh
#!/bin/shecho "$0 "echo "$1 "echo "$2 "-bash-4.2$ ./test1.sh a b c./test1.sh a b -bash-4.2$本博客全部内容是原创,假设转载请注明来源
显示全部命令行參数
-bash-4.2$ cat test1.sh
#!/bin/shuntil [ -z "$1" ]do echo "$1 " shiftdone-bash-4.2$ ./test1.sh a b c d e fa b c d e f-bash-4.2$ cat test1.sh
#!/bin/shindex=1for myarg in $*do echo "NO#$index=$myarg" let "index+=1"done-bash-4.2$ ./test1.sh a b c d e fNO#1=aNO#2=bNO#3=cNO#4=dNO#5=eNO#6=f-bash-4.2$条件表达式
-bash-4.2$ cat test1.sh
#!/bin/sha=1b=2if [ $a -gt $b ]then echo "GT"else echo "LT"fi-bash-4.2$ ./test1.shLT-bash-4.2$-bash-4.2$ cat test1.sh
#!/bin/sha=2b=2if [ $a -gt $b ]then echo "GT"elif [ $a -eq $b ]then echo "eq"else echo "LT"fi-bash-4.2$ ./test1.sheq-bash-4.2$-bash-4.2$ cat test1.sh
#!/bin/shecho "====================="echo "1.a"echo "2.b"echo "3.c"read mychoicecase $mychoice in 1 ) echo "a";; 2 ) echo "b";; 3 ) echo "c";;esacexit 0-bash-4.2$ ./test1.sh=====================1.a2.b3.c2b-bash-4.2$循环
-bash-4.2$ cat test1.sh
#!/bin/shfor filename in `ls`do echo $filenamedone-bash-4.2$ ./test1.sh1abcabderror.loghadoop-2.4.1hadoop-2.4.1-src.tar.gzhadoop-2.4.1.tar.gzhellomydoclist显示全部偶数
:和true都表示为真的意思
-bash-4.2$ cat test1.sh
#!/bin/sh
a=0
while :
do
let "a=$a + 1"
if[ $a -gt 20 ]
then
break
fi
if[ $(($a%2)) -eq 1 ]
then
continue
fi
echo $a
done
-bash-4.2$ ./test1.sh
2
4
6
8
10
12
14
16
18
20
-bash-4.2$