大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。
shell命令行参数
-bash-4.2$ cat test1.sh
#!/bin/sh
echo “$0 “
echo “$1 “
echo “$2 “
-bash-4.2$ ./test1.sh a b c
./test1.sh
a
b
-bash-4.2$
本博客全部内容是原创,假设转载请注明来源
http://blog.csdn.net/myhaspl/
显示全部命令行參数
-bash-4.2$ cat test1.sh
#!/bin/sh
until [ -z “$1” ]
do
echo “$1 “
shift
done
-bash-4.2$ ./test1.sh a b c d e f
a
b
c
d
e
f
-bash-4.2$ cat test1.sh
#!/bin/sh
index=1
for myarg in $*
do
echo “NO#$index=$myarg”
let “index+=1”
done
-bash-4.2$ ./test1.sh a b c d e f
NO#1=a
NO#2=b
NO#3=c
NO#4=d
NO#5=e
NO#6=f
-bash-4.2$
条件表达式
-bash-4.2$ cat test1.sh
#!/bin/sh
a=1
b=2
if [ $a -gt $b ]
then
echo “GT”
else
echo “LT”
fi
-bash-4.2$ ./test1.sh
LT
-bash-4.2$
-bash-4.2$ cat test1.sh
#!/bin/sh
a=2
b=2
if [ $a -gt $b ]
then
echo “GT”
elif [ $a -eq $b ]
then
echo “eq”
else
echo “LT”
fi
-bash-4.2$ ./test1.sh
eq
-bash-4.2$
-bash-4.2$ cat test1.sh
#!/bin/sh
echo “=====================”
echo “1.a”
echo “2.b”
echo “3.c”
read mychoice
case $mychoice in
1 ) echo “a”;;
2 ) echo “b”;;
3 ) echo “c”;;
esac
exit 0
-bash-4.2$ ./test1.sh
=====================
1.a
2.b
3.c
2
b
-bash-4.2$
循环
-bash-4.2$ cat test1.sh
#!/bin/sh
for filename in `ls`
do
echo $filename
done
-bash-4.2$ ./test1.sh
1
abc
abd
error.log
hadoop-2.4.1
hadoop-2.4.1-src.tar.gz
hadoop-2.4.1.tar.gz
hello
mydoclist
显示全部偶数
:和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$
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/116695.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...