当前位置: 首页 > news >正文

上小学网站建设黑龙江建设网官网网上服务大厅

上小学网站建设,黑龙江建设网官网网上服务大厅,网站建设开发定制,深圳建设工程交易服务网站概念 shell的条件测试目的是得出真和假。 shell 提供的条件测试语法 test 命令 [] 中括号命令 语法*#xff1a; test条件测试 test命令用来评估一个表达式#xff0c;他的结果是真#xff0c;还是假#xff0c;如果条件为真#xff0c;那么命令执行状态结果就为0 test条件测试 test命令用来评估一个表达式他的结果是真还是假如果条件为真那么命令执行状态结果就为0否则就是不为0通过$?取值。 test命令参数 检测给定文件名是否存在 -e 判断该文件是否存在普通文件目录存在就为真否则为假 检测给定文件名的类型 -f 判断该文件名是否为文件 -d 判断该文件名是否为目录 -b 判断该文件名是否为块设备 -c 判断该文件名是否为字符设备 -s 判断该文件名是否为socket -p 判断该文件名是否为管道FIFO -L 判断该文件名是否为连接 检测文件的权限 -r 判断该文件名是否可读 -w 判断该文件名是否可写 -x 判断该文件名是否可运行 -u 判断该文件名是否有SUID属性 -g 判断该文件名是否有SGID属性 -k 判断该文件名是否有Sticky bit属性 -s 判断该文件名是否为空白文件 文件比较 如test file1 -nt file2 -nt newer than判断file1是否比file2新 -otolder than判断file1是否比file2旧 -ef 判断file1与file2是否为同一个文件可用在判断hard link的判定上主要意义在判定两个文件是否均指向同一个inode 整数之间判定 -eq 两数值相等 -ne 两数值不等 -gt n1大于n2 greater than -lt n1小于n2less than -ge n1大于等于n2 greater than or equal -le n1小于等于n2less than or equal 判定字符串数据 -z 判断字符串是否为0若字符串为空则为true -n 判断字符串是否为非0若字符串为非空则为true 判断str1与str2是否相等相等则为true ! 判断str1与str2是否不想等不相等则为true 多重条件判断 -a and两状态同时成立则返回true -o or两状态任意一个成立则返回true ! 反向状态 test命令实践 -e演示 xiao123xiao123:~/Downloads/shscripts$ test -e del_data.sh xiao123xiao123:~/Downloads/shscripts$ echo $? 0 xiao123xiao123:~/Downloads/shscripts$ test -e del_data.sh12 xiao123xiao123:~/Downloads/shscripts$ echo $? 1 xiao123xiao123:~/Downloads/shscripts$ xiao123xiao123:~/Downloads/shscripts$ test -e del_data.sh echo 文件已存在 文件已存在 xiao123xiao123:~/Downloads/shscripts$ test -e del_data.sh12 echo 文件已存在 xiao123xiao123:~/Downloads/shscripts$ test -e del_data.sh12 || echo 文件不存在 文件不存在 xiao123xiao123:~/Downloads/shscripts$ xiao123xiao123:~/Downloads/shscripts$ test -e hello echo 该文件/目录已存在不再执行创建动作 || mkdir hello xiao123xiao123:~/Downloads/shscripts$ test -e hello echo 该文件/目录已存在不再执行创建动作 || mkdir hello 该文件/目录已存在不再执行创建动作 xiao123xiao123:~/Downloads/shscripts$-f演示 xiao123xiao123:~/Downloads/shscripts$ ls calculation.sh chaochao_5_finished.png index.html.11 index.html.2 index.html.28 index.html.6 chaochao_1_finished.png chaochao_5.jpg index.html.12 index.html.20 index.html.29 index.html.7 chaochao_1.jpg del_data.sh index.html.13 index.html.21 index.html.3 index.html.8 chaochao_2_finished.png expr_test1.sh index.html.14 index.html.22 index.html.30 index.html.9 chaochao_2.jpg expr_test.sh index.html.15 index.html.23 index.html.31 let_test.sh chaochao_3_finished.png hello index.html.16 index.html.24 index.html.32 chaochao_3.jpg index.html index.html.17 index.html.25 index.html.33 chaochao_4_finished.png index.html.1 index.html.18 index.html.26 index.html.4 chaochao_4.jpg index.html.10 index.html.19 index.html.27 index.html.5 xiao123xiao123:~/Downloads/shscripts$ test -f hello echo ok || echo no no xiao123xiao123:~/Downloads/shscripts$-d演示 xiao123xiao123:~/Downloads/shscripts$ ls calculation.sh chaochao_5_finished.png index.html.11 index.html.2 index.html.28 index.html.6 chaochao_1_finished.png chaochao_5.jpg index.html.12 index.html.20 index.html.29 index.html.7 chaochao_1.jpg del_data.sh index.html.13 index.html.21 index.html.3 index.html.8 chaochao_2_finished.png expr_test1.sh index.html.14 index.html.22 index.html.30 index.html.9 chaochao_2.jpg expr_test.sh index.html.15 index.html.23 index.html.31 let_test.sh chaochao_3_finished.png hello index.html.16 index.html.24 index.html.32 chaochao_3.jpg index.html index.html.17 index.html.25 index.html.33 chaochao_4_finished.png index.html.1 index.html.18 index.html.26 index.html.4 chaochao_4.jpg index.html.10 index.html.19 index.html.27 index.html.5 xiao123xiao123:~/Downloads/shscripts$ test -d hello echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$-z/-n演示 xiao123xiao123:~/Downloads/shscripts$ test -d hello echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$ test -z echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$ test -z echo ok || echo no no xiao123xiao123:~/Downloads/shscripts$ test -n echo ok || echo no no xiao123xiao123:~/Downloads/shscripts$ test -n echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$中括号条件测试 脚本中经常进行条件测试用的最多的都是中括号。 test和[]的作用是一样的。 注意点中括号前后都要有空格[ ] [ -n “${filename}” ] 注意在条件测试中使用变量必须要添加双引号 xiao123xiao123:~/Downloads/shscripts$ filedel_data.sh xiao123xiao123:~/Downloads/shscripts$ [ -f ${file} ] echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$ filedel_data.sh12 xiao123xiao123:~/Downloads/shscripts$ [ -f ${file} ] echo ok || echo no no xiao123xiao123:~/Downloads/shscripts$双中括号条件测试 双中括号增加了正则表达式的支持其他与中括号相同。 变量测试 把字符串写入变量中 对变量测试必须要加双引号 xiao123xiao123:~/Downloads/shscripts$ file1鸡你太美.jpg xiao123xiao123:~/Downloads/shscripts$ [[ -f ${file1} ]] echo 我是两年半的练习生鸡你太美 || echo 我是个好人 我是个好人 xiao123xiao123:~/Downloads/shscripts$ [[ -f ${file1} ]] echo 我是两年半的练习生鸡你太美 || echo 我是个好人 我是个好人 xiao123xiao123:~/Downloads/shscripts$ touch 鸡你太美.jpg xiao123xiao123:~/Downloads/shscripts$ [[ -f ${file1} ]] echo 我是两年半的练习生鸡你太美 || echo 我是个好人 我是两年半的练习生鸡你太美 xiao123xiao123:~/Downloads/shscripts$字符串测试 比较两个字符串变量的值是否相等不等的情况。 判断是否相等 ! 判断不相等 ! 取结果的反义颠倒黑白 注意: 对于字符串变量的比较一定要给变量添加双引号 使用等于号判断左右两边必须有空格 演示 xiao123xiao123:~/Downloads/shscripts$ [ ! -f 糖果超甜组合.txt ] echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$ [ -f 糖果超甜组合.txt ] echo ok || echo no no xiao123xiao123:~/Downloads/shscripts$数值比较测试 操作方式 在中括号以及test中数值比较的用法 在中括号中使用数学比较符号请添加转义符号 xiao123xiao123:~/Downloads/shscripts$ [ 2 1 ] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [ 1 2 ] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [ 1 \ 2 ] echo yes || echo no no xiao123xiao123:~/Downloads/shscripts$ xiao123xiao123:~/Downloads/shscripts$ [ 2 \ 2 ] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [ 2 ! 2 ] echo yes || echo no no #不等于可以不用添加转义 xiao123xiao123:~/Downloads/shscripts$ [ 3 ! 2 ] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [ 3 \! 2 ] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [ 3 \!\ 2 ] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [ 3 \!\ 3 ] echo yes || echo no no xiao123xiao123:~/Downloads/shscripts$双中括号 对中括号的补充双中括号还支持正则处理。 在双中括号中不要转义字符。 xiao123xiao123:~/Downloads/shscripts$ [[ 5 6 ]] echo yes || echo no no xiao123xiao123:~/Downloads/shscripts$ [[ 5 6 ]] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [[ 5 6 ]] echo yes || echo no no xiao123xiao123:~/Downloads/shscripts$ [[ 5 ! 6 ]] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [[ 5 -ge 6 ]] echo yes || echo no no xiao123xiao123:~/Downloads/shscripts$ [[ 5 -le 6 ]] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$ [[ 5 -gt 6 ]] echo yes || echo no no xiao123xiao123:~/Downloads/shscripts$ [[ 5 -lt 6 ]] echo yes || echo no yes xiao123xiao123:~/Downloads/shscripts$逻辑操作符号测试 -a 与运算 两边都为真结果才为真 || -o 或运算两边有一个为真结果为真 中括号逻辑运算比较 xiao123xiao123:~/Downloads/shscripts$ file1/etc/init.d/rsync xiao123xiao123:~/Downloads/shscripts$ file2/etc/hostname xiao123xiao123:~/Downloads/shscripts$ [ -f ${file1} -a -f ${file2} ] echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$ file1/tmp/sqqqq xiao123xiao123:~/Downloads/shscripts$ [ -f ${file1} -a -f ${file2} ] echo ok || echo no no xiao123xiao123:~/Downloads/shscripts$ [ -f ${file1} -o -f ${file2} ] echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$双中括号运算比较 xiao123xiao123:~/Downloads/shscripts$ str1 xiao123xiao123:~/Downloads/shscripts$ str2yuyu xiao123xiao123:~/Downloads/shscripts$ [[ -n ${str1} -n ${str2} ]] echo ok || echo no no xiao123xiao123:~/Downloads/shscripts$ [[ -n ${str1} || -n ${str2} ]] echo ok || echo no ok xiao123xiao123:~/Downloads/shscripts$脚本开发 要求接收用户输入判断它是否等于某个数字。 xiao123xiao123:~/Downloads/shscripts$ bash ./test_input.sh Please input a char: 3 脚本出错必须输入1和2 xiao123xiao123:~/Downloads/shscripts$ bash ./test_input.sh Please input a char: 1 1 xiao123xiao123:~/Downloads/shscripts$ bash ./test_input.sh Please input a char: 2 2 xiao123xiao123:~/Downloads/shscripts$ cat ./test_input.sh #! /bin/bashread -p Please input a char: var1[ ${var1} -eq 1 ] {echo ${var1}exit 0 }[[ ${var1} 2 ]] {echo ${var1}exit 0 }[ ${var1} ! 2 -a ${var1} ! 1 ] {echo 脚本出错必须输入1和2exit 1 } xiao123xiao123:~/Downloads/shscripts$要求安装lnmp/lamp脚本开发。 xiao123xiao123:~/Downloads/shscripts$ mkdir test xiao123xiao123:~/Downloads/shscripts$ echo echo LAMP is installed ./test/lamp.sh xiao123xiao123:~/Downloads/shscripts$ echo echo LNMP is installed ./test/lnmp.sh xiao123xiao123:~/Downloads/shscripts$ chmod x ./test/lamp.sh xiao123xiao123:~/Downloads/shscripts$ chmod x ./test/lnmp.sh xiao123xiao123:~/Downloads/shscripts$源码 xiao123xiao123:~/Downloads/shscripts$ cat ./test_install.sh #! /bin/bashpath./test[ ! -d ${path} ] mkdir ${path} -pcat END1. [install lamp]2. [install lnmp]3. [exit]please input the num you want: ENDread numexpr ${num} 1 /dev/null[ $? -ne 0 ] {echo input number must be {1|2|3}exit 1 }[ ${num} -eq 1 ] {echo Strating installing lamp.....waiting...sleep 2[ -x ${path}/lamp.sh ] || {echo The file does not exist or cant be execut.exit 1}${path}/lamp.shexit $? }[ ${num} -eq 2 ] {echo Strating installing lnmp.....waiting...sleep 2[ -x ${path}/lamp.sh ] || {echo The file does not exist or cant be execut.exit 1}${path}/lnmp.shexit $? }[ ${num} -eq 3 ] {echo byebyeexit 3 }[[ ! ${num} ~ [1-3] ]] {echo The number input must be {1|2|3}exit 4 } xiao123xiao123:~/Downloads/shscripts$运行结果 xiao123xiao123:~/Downloads/shscripts$ bash ./test_install.sh1. [install lamp]2. [install lnmp]3. [exit]please input the num you want: e input number must be {1|2|3} xiao123xiao123:~/Downloads/shscripts$ bash ./test_install.sh1. [install lamp]2. [install lnmp]3. [exit]please input the num you want: 3 byebye xiao123xiao123:~/Downloads/shscripts$ bash ./test_install.sh1. [install lamp]2. [install lnmp]3. [exit]please input the num you want: 1 Strating installing lamp.....waiting... LAMP is installed xiao123xiao123:~/Downloads/shscripts$ bash ./test_install.sh1. [install lamp]2. [install lnmp]3. [exit]please input the num you want: 2 Strating installing lnmp.....waiting... LNMP is installed xiao123xiao123:~/Downloads/shscripts$
http://www.hkea.cn/news/14311841/

相关文章:

  • 做网站公司叫什么住房和城乡建设部网站倪虹
  • 网站建设进什么科目易支付对接WordPress
  • 网站开发技术三大件wordpress 瀑布流分页
  • 建设企业网站费用公司设计一个网站需要多久
  • 太原网站建设技术托管上传资料网站
  • 带数据库的网页怎么制作网站怎么做排名优化
  • 东莞微信网站建设推荐wordpress exploit
  • 海口网站开发师招聘列举五种常用的网站推广方法
  • 静态网站建设的主要技术百度排名点击软件
  • 周口网站建设泰安人才信息网官网
  • 做网站的公司合肥wordpress 插件 文章
  • 常见网站模式东莞 网站 建设 汽车
  • 戴尔公司网站建设成功的关键是什么浅议我国旅游景点网站的建设
  • wordpress 微网站模板2022企业所得税优惠政策
  • 百度宣传推广大连seo关键词排名
  • 雕刻业务网站怎么做成都网页制作培训机构
  • 贵阳网站开发哪家便宜前几年做那些网站能致富
  • 国外优秀企业网站赣州91人才网赣州招聘信息
  • 合肥网站推广 公司哪家好直接下载app到手机上
  • 做彩妆发哪个网站浏览量高深圳网站建设哪个最好
  • 小程序源码之家网站建设及优化方案
  • 医院网站后台管理系统登录网站制作二级网页怎么做
  • 0基础学网站设计制图平台
  • 管理系统网站模板旅游网站开发系统分析
  • 临沂网站开发公司电话怎样做网站吸引客户
  • 建设特效网站图片在线设计网站
  • 南京建设教育网站wordpress火车头插件防重复
  • 泸州免费做网站重庆百度竞价推广
  • 公司免费建网站网站排名带照片怎么做
  • 静海网站建设制作wordpress 手机版主题