arr=(1 2 3 4 5)
arr=(燕睿涛 yrt lulu yanruitao)
arr=('^[0-9]+$' '^yrt\.(\d+)\.log$')
arr=(
"燕睿涛" \
"yanruitao" \
"today is a good day!"
)
len=${#arr[@]} #返回的是数组元素的个数
echo ${arr[0]} #数组中的第一个元素,这个和其他语言的数组类似,下表从0开始
echo ${arr[2]} #数组中的第3个元素
[yanruitao@boss_runtime sh]$ arr=(
> "燕睿涛"
> "http:\/\/www\.baidu\.com\/(\d+)\.html"
> "yanruitao"
> "lulu"
> "yrt"
> )
[yanruitao@boss_runtime sh]$ echo ${#arr[@]}
5
[yanruitao@boss_runtime sh]$ echo ${arr[1]}
http:\/\/www\.baidu\.com\/(\d+)\.html
[yanruitao@boss_runtime sh]$ echo ${arr[0]}
燕睿涛
[yanruitao@boss_runtime sh]$ echo ${arr[5]}
[yanruitao@boss_runtime sh]$
#第一种(()) if((6 <8)); then echo "yes 燕睿涛"; fi #输出——yes 燕睿涛 if(($a>8)); then echo "yes 燕睿涛"; fi if(($a<=$b)); then echo "yes 燕睿涛"; fi #第二种[] [[]] if [ 2 -gt 1 ]; then echo "iforever 燕睿涛"; fi if [[ 'abc' > 'ab' ]]; then echo "iforever 燕睿涛"; fi #iforever 燕睿涛 if [[ 2 < 10 ]]; then echo "iforever 燕睿涛"; fi #无输出 if [[ 2 -lt 10 ]]; then echo "iforever 燕睿涛"; fi #iforever 燕睿涛
#看看小括号的用法,首先是在for循环里面,相当于还是数学计算 [yanruitao@boss_runtime ad]$ for((a=0;a<10;a++)) > do > echo $a > done 0 1 2 3 4 5 6 7 8 9 #对变量进行++,还是相当于数序运算 [yanruitao@boss_runtime ad]$ i=1 [yanruitao@boss_runtime ad]$ echo $i 1 [yanruitao@boss_runtime ad]$ let i++ [yanruitao@boss_runtime ad]$ echo $i 2 [yanruitao@boss_runtime ad]$ ((i++)) [yanruitao@boss_runtime ad]$ echo $i 3 #数学运算 [yanruitao@boss_runtime ad]$ echo 1+2 1+2 [yanruitao@boss_runtime ad]$ echo $((1+2)) 3 #单括号里面是一个命令组,括号中的命令将会新开一个shell顺序执行,所以这个里面相当于一个封闭的空间,里面的变量什么的不能被剩余代码使用 [yanruitao@boss_runtime ad]$ a=1 [yanruitao@boss_runtime ad]$ (a=3;echo $a) 3 [yanruitao@boss_runtime ad]$ echo $a 1 #括号中and的使用 if [[ -n "$ret" && $ret -gt 123 ]]... #[[]]双中括号中只能使用&&,不能使用-a if [ -n "$ret" -a $ret -gt 123 ]... #[]单中括号中只能使用-a,不能使用&& if(($ret)) && (($ret >123 ))... #(())双小括号使用&&
function getId()
{
local url=$1 #local限定了变量url的作用域只在函数里面,不然会污染全局的作用域
ereg="http:\/\/www\.baidu\.com\/\([0-9]\+\)\.html"
local ret=$(expr $url : $ereg)
if [[ -n "$ret" && $ret -gt 0 ]]; then #当ret为null时使用[]会报错,-n这里的双引号一定要加上,不然当$ret为null时,一直返回真
echo $ret
return 0
fi
return 1
}
[yanruitao@boss_runtime sh]$ echo $?
0
[yanruitao@boss_runtime sh]$ getId "http://www.baidu.com/123.htl"
[yanruitao@boss_runtime sh]$ echo $?
1
[yanruitao@boss_runtime sh]$ getId "http://www.baidu.com/123.html"
123
[yanruitao@boss_runtime sh]$ echo $?
0
[yanruitao@boss_runtime sh]$ str="燕睿涛 lulu yrt yanruitao"
[yanruitao@boss_runtime sh]$ arr=($str) #这一步将字符串转化为了数组
[yanruitao@boss_runtime sh]$ echo ${arr[*]}
燕睿涛 lulu yrt yanruitao
[yanruitao@boss_runtime sh]$ echo ${#arr[@]}
4
& #在一个命令的最后加上这个命令,可以将该命令放到后台执行 ./update.sh 100 500 & ctrl + z #讲一个正在前台执行的命令放到后台,并且处于暂停状态 jobs #查看当前后台运行的命令 jobs -l #可以显示所有后台任务的PID [yanruitao@boss_runtime sh]$ jobs -l [1] 9681 Running ./t.sh 100 300 & [2] 9683 Running ./t.sh 100 300 & [3]- 9685 Running ./t.sh 100 300 & [4]+ 9688 Running ./t.sh 100 300 & fg #把后台中的命令调至前台继续运行,如果后台有多个命令可以使用`fg %jobnumber`将选中命令调出 [yanruitao@boss_runtime sh]$ jobs -l [2] 10033 Running ./t.sh 100 300 & [3] 10035 Running ./t.sh 100 300 & [4]- 10037 Running ./t.sh 100 300 & [5]+ 10039 Running ./t.sh 100 300 & [yanruitao@boss_runtime sh]$ fg %2 ./t.sh 100 300 bg #讲一个在后台暂停的命令变成在后台继续执行。同样,如果有多个命令,可以使用bg %jobnumber [yanruitao@boss_runtime sh]$ jobs -l [1]- 11655 Running ./t.sh 100 300 & [2]+ 11662 Running ./t.sh 100 300 & [yanruitao@boss_runtime sh]$ fg %1 ./t.sh 100 300 ^Z [1]+ Stopped ./t.sh 100 300 [yanruitao@boss_runtime sh]$ jobs -l [1]+ 11655 Stopped ./t.sh 100 300 [2]- 11662 Running ./t.sh 100 300 & [yanruitao@boss_runtime sh]$ bg %1 [1]+ ./t.sh 100 300 & [yanruitao@boss_runtime sh]$ jobs -l [1]- 11655 Running ./t.sh 100 300 & [2]+ 11662 Running ./t.sh 100 300 & kill #终止进程 kill %num #通过jobs查看的job号,进行杀死 kill pid #通过进程号杀掉进程 ctrl + C #终止当前前台的进程
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有