为了账号安全,请及时绑定邮箱和手机立即绑定
  • 老师,是不是特别喜欢凤姐啊?每段视频都有她。
    查看全部
  • #!/bin/bash read -t 30 -p "Please input num1: " num1 read -t 30 -p "Please input num2: " num2 read -t 30 -p "Please input a operator: " ope if [ -n "$num1" -a -n "$num2" -a -n "$ope" ] then test1=$(echo $num1 | sed 's/[0-9]//g') test2=$(echo $num2 | sed 's/[0-9]//g') if [ -z "$test1" -a -z "$test2" ] then if ["$ope" == '+'] then sum=$(($num1+$num2)) elif ["$ope" == '-'] then sum=$(($num1-$num2)) elif ["$ope" == '*'] then sum=$(($num1*$num2)) elif ["$ope" == '*'] then sum=$(($num1*$num2)) elif ["$ope" == '*'] then sum=$(($num1*$num2))
    查看全部
  • [root@imooc wenjian]# aa=11 [root@imooc wenjian]# bb=22 [root@imooc wenjian]# echo $aa 11 [root@imooc wenjian]# echo $bb 22 [root@imooc wenjian]# [ "$aa" =="$bb" ]&&echo yes ||echo no -bash: [: 11: unary operator expected no [root@imooc wenjian]# [ "$aa" =="$bb" ]&&echo yes ||echo no -bash: [: 11: unary operator expected no [root@imooc wenjian]# [ "$aa" == "$bb" ]&&echo yes ||echo no no [root@imooc wenjian]# [ "$aa"=="$bb" ]&&echo yes ||echo no yes [root@imooc wenjian]# [ "$aa" == "$bb" ]&&echo yes ||echo no no 这里面有好多要空格的地方,如果没有空格的话,结果会很不同哦
    查看全部
  • #判断apache服务是否启动 test=$(ps aux |grep httpd |grep -v grep) #定义变量test 并且查找是否启动apache的结果赋值给test #ps aux 查看当前所有正在运行的进程 #grep httpd 过滤出apache进程 #grep -v grep 去掉包含grep的进程 -v 取反 if [ -n "$test" ] #判断test是否为空 then #如果不为空则执行这段程序 把结果写入/tmp/autostart-acc.log 中 echo " $(date) httpd is ok " >> /tmp/autostart-acc.log else #如果为空这执行这段程序 #首先启动httpd服务 systemctl start httpd.service #然后把事件记录在错误日志中 echo " $(date) httpd is no \n httpd is autostart now" >> /tmp/autostart-err.log fi
    查看全部
  • file1 -nt file2:判断文件1的修改时间是否比文件2的新 file1 -ot file2:判断文件1的修改时间是否比文件2的旧 file1 -ef file2:判断文件1是否比文件2的Inode号一致,可以理解为两个文件是否为同一个文件。 ln /root/student.txt /tmp/stu.txt #创建硬链接
    查看全部
  • #!/bin/bash read -t 30 -p "Please input num1: " num1 read -t 30 -p "Please input num2: " num2 #通过 read -t 30 -p "Please input a operator: " ope #通过 if [ -n "$num1" -a -n "$num2" -a -n "$ope" ] #第一层判断 then test1=$(echo $num1 sed 's/[0-9]//g') test2=$(echo $num2 sed 's/[0-9]//g') if [ -z "$test1" -a -z "$test2" ] #第二层判断,用来判断num1和num2的值为数值 #如果test1和test2的值为空,则证明num1和num2为数字 then #如果num1和num2为数字,则执行以下命令 if [ "$ope" == '+' ] #第三层判断用来确认运算符,测试变量$ope中是什么运算符 then sum=$(($num1 + $num2 )) elif [ "$ope" == '-' ] then sum=$(($num1 - $num2)) elif [ "$ope" == '*' ] then sum=$(($num1 * $num2)) elif [ "ope" == '/' ] then sum=$(($num1 / $num2)) else echo "Please enter a valid symbol!" #如果运算符不匹配,提示输入有效的符号 exit 10 #并退出程序,返回错误代码10。通过echo $?查看 fi else echo "Please enter a valid value!" #如果test1和test2的值不为空,则说明num1和num2不是数字 exit 11 #并退出程序,返回错误代码11 fi fi echo "$num1 $ope $num2 = $sum" #输出数值运算结果
    查看全部
  • #!/bin/bash read -t 30 -p "Please input num1:" num1 read -t 30 -p "Please input num2:" num2 read -t 30 -p "Please input operator:" ope if [ -n "$num1" -a -n "$num2" -a -n "$ope" ] then test1=$(echo $num1 | sed 's/[0-9]//g') test2=$(echo $num2 | sed 's/[0-9]//g') if [ -z "$test1" -a -z "$test2" ] then if [ "$ope" == '+' ] then result=$(($num1+$num2)) elif [ "$ope" == '-' ] then result=$(($num1-$num2)) elif [ "$ope" == '/' ] then result=$(($num1 / $num2)) elif [ "$ope" == '*' ] then result=$(($num1*num2)) else echo "Error: the input operator is worng, please input +-*/" exit 111 fi else echo "Error: Please input numbers!" exit 222 fi echo "$num1 $ope $num2 is $result" else echo "Error: You input null value!" exit 333 fi
    查看全部
  • #!/bin/bash read -p "Please input your firstnum:" num1 read -p "Please input your secondnu:" num2 read -p "please input your operation:" ope test1=$(echo $num1 | grep "[^0-9]") test2=$(echo $num2 | grep "[^0-9]") if [ -z "$num1" -o -z "$num2" -o -z "$ope" ] then echo "Input is NULL" exit 10 #查看输入是否为空 fi if [ -n "$test1" -o -n "$test2" ] then echo "Input is not number" exit 11 fi #查看输入的是否是数字 if [ "$ope" == '+' ] then result=$(($num1 + $num2)) elif [ "$ope" == '-' ] then result=$(($num1 - $num2)) elif [ "$ope" == '*' ] then result=$(($num1 * $num2)) elif [ "$ope" == '/' ] then result=$(($num1 / $num2)) else echo "Ope is error" exit 12 fi echo "$num1 $ope $num2 = $result"
    查看全部
  • 【if组合for循环实例】 #!/bin/bash #批量添加指定数量的用户实例 read -t 30 -p "input user name:" name read -t 30 -p "input password:" pass read -t 30 -p "input user number:" num #检查输入内容是否为非空 if [ -n "$name" -a -n "$pass" -a -n "$num" ] then #检查输入的用户数量是否为纯数字 chknum=$( echo "$num" | sed 's/[0-9]//g' ) if [ -z "$chknum" ] then for (( i=1;i<="$num";i=i+1 )) do #添加用户 /usr/sbin/useradd $name$i #添加用户密码,passwd 的--stdin参数是非交互输入,直接传入密码,不需要第二次确认 echo $pass | /usr/bin/passwd --stdin $name$i echo "add $i" done else echo "the num must be number" fi else echo "must be input name pass num" fi
    查看全部
  • 【多分支语句case】 格式: case $变量名 in "值1") 如果变量值等于值1,执行程序1 ;; "值2") 如果变量值等于值2,执行程序2 ;; …… …… *) 如果变量值都不是以上值,则执行此程序 ;; esac #与if多分支最大区别是,case语句只能判断一种条件关系,而if语句可以判断多种条件关系 【case 实例】 #!/bin/bash #case实例,选择课程 echo "1 : yuwen" echo "2 : shuxue" echo "3 : yingyu" read -t 30 -p "choose kecheng:" cho case $cho in "1") echo "choose yuwen." ;; "2") echo "choose shuxue." ;; "3") echo "choose yingyu" ;; *) echo "choose wrong" ;; esac
    查看全部
  • 【字符串的判断】 -z 字符串 #判断字符串是否为空,为空返回真 -n 字符串 #判断字符串是否为非空,非空返回真 字符串1 == 字符串2 #判断两字符串是否相等,相等返回真,==左右加空格 字符串1 != 字符串2 #判断两字符串是否不相等,不相等返回真,!=左右加空格 实例: [root@CentOS ~]# aa=123 #变量赋值 [root@CentOS ~]# bb=234 #变量赋值 [root@CentOS ~]# [ "$aa" == "$bb" ] && echo yes || echo no no [root@CentOS ~]# bb=123 [root@CentOS ~]# [ "$aa" == "$bb" ] && echo yes || echo no yes
    查看全部
  • 第二章 单分支if语句 2.3 判断分区使用率 #根分区的使用率 #1.定义变量rate 的值等于/dev/sda1的使用率 rate=$( df -h |grep "/dev/sda1" | awk '{ print $5 }' | cut -d "%" -f 1 ) #df -h 查看磁盘信息 输结果用grep进行行过滤 再 将过滤的结果用 awk进行列过滤 将列过滤的值再 用cut进>行列过滤 最后得出纯数值 #grep 进行行过滤 过滤出/dev/sda1这一行数据 #awk '{ print $5 }' 截取第五列的数值 #cut -d "%" -f 1 截取第一列的值以%作为分隔符 echo $rate #输出 rate变量的值 调试使用 if [ "$rate" -ge "20" ] # [ "$rate" -ge "20" ] 判断rate是否大于等于20 then #如果条件成立 则执行程序 echo "warning! /dev/sda1 is full !!" fi #结束if
    查看全部
  • equal no equal giant than less than giant or equal less or equal 不知道对不对,这样容易记忆
    查看全部
  • 多分枝IF条件语句
    查看全部
  • 学习小脚本实例的好处:

         1、掌握语法结构

         2、了解shel的作用

         3、分析编程思想

    建立编程思想的方法:

         1、熟悉Linux基本命令、规范、语法及shell语法

         2、当遇到实际需求时,应用所学知识

    如何“背”程序?

         1、抄写老师的程序并能正确运行

         2、为程序补全注释

         3、删掉注释,为代码重新加注释

         4、看注释写代码

         5、删掉代码和注释,从头开始写

        

    查看全部
首页上一页1234567下一页尾页

举报

0/150
提交
取消
课程须知
小伙伴们,学习本课程前需要掌握Linux常用命令,并学习《Tony老师聊shell》系列的前四门课程呦!
老师告诉你能学到什么?
1、掌握条件判断和流程控制的基本语句 2、通过大量案例的学习,掌握shell编程思想 3、体会shell编程在Linux运维中的重要作用

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!