摘要:bash中如何实现条件判断?条件测试类型: 整数测试 字符测试 文件测试 一、条件测试的表达式: [ expression ] 括号两端必须要有空格 [[ expression ]] 括号两端必须要有空格 test expression组合测试条件: -a: and -o: or !: 非 二、整数
        阅读全文
        随笔分类 - shell
shell编写
摘要:sed命令小结: 替换命令ssed -r 's/west/north/g' datafilesed -r 's/^west/north/' datafilesed -r 's/[0-9][0-9]$/&.5/' datafilesed -r 's/(Mar)got/\1ianne/g' datafi
        阅读全文
        
摘要:if格式{if(表达式){语句1;语句2;……}}{if(表达式){语句1;语句2,……}else{语句1;语句2,……}}{if(表达式){语句}else if(表达式){语句}else if(表达式){语句}else{语句}} awk -F: '{if($3<0 && $3<1000){i++}
        阅读全文
        
摘要:awk是文本处理工具,功能小结如下: 1、条件表达式 [root@centos17 shell]# awk -F: '$3>1&&$3<3{print $0}' /etc/passwd daemon:x:2:2:daemon:/sbin:/sbin/nologin [root@centos17 sh
        阅读全文
        
摘要:阶乘计算 版本一: [root@centos17 shell]# sh -v factorial.sh #!/bin/bash factorial() { factorial1=1 for((i=1;i<=5;i++));do factorial1=$((factorial1*i)) done ec
        阅读全文
        
摘要:#!/bin/bash 官方推荐写法 #/usr/bin/env bash 最好的写法 #!/usr/bin/bash #!/bin/sh #!/usr/sh 后三种写法,根据不同的linux版本,路径会有所改变导致程序无法识别。可以使用#/usr/bin/env bash来替代。
        阅读全文
        
摘要:关联数组 [root@centos17 shell]# cat shells_count.sh #!/bin/bash #login shell counts declare -A shells while read line do type=`echo $line|awk -F":" '{prin
        阅读全文
        
摘要:对于表达式来说:i++是先赋值再加1,++i是先加1再赋值 对于i变量本身来说:结果一样 测试结果如下: [root@centos17 ~]# unset a [root@centos17 ~]# unset b [root@centos17 ~]# echo $a [root@centos17 ~
        阅读全文
        
摘要:shell数组变量: 普通数组:只能使用整数作为数组索引 关联数组:可以使用字符串作为数组索引 数组变量与普通变量对比: 普通变量:只能存储一个值 数组变量:可以存储多个值 例如: name=playgame 变量 |p |l |a |y |g |a |m |e |0 |1 |2 |3 |4 |5 
        阅读全文
        
摘要:自定义变量,只在当前shell下生效。在编写脚本时,一般将公共的变量参数写到publish.sh脚本中,其他子功能的shell脚本,只需要执行. publish.sh 即可调用公共脚本里面定义的参数。所以,一般用不到环境变量。脚本变量调用关系如下图所示: 环境变量,在所有shell下都生效,可以在任
        阅读全文
        
摘要:使用rsync进行简单的数据远程备份脚本 一、实验环境:1、centos-A网站服务器:192.168.0.101/24提前准备好网站源代码和数据库2、centos-B备份服务器:192.168.0.102/24 二、ssh客户端centos-A生成公钥和私钥对ssh-keygen -t rsa 命
        阅读全文
        
摘要:[root@x112 software]# unzip -l LAMP_centos7.4.zip Archive: LAMP_centos7.4.zip Length Date Time Name 1031613 04-10-2017 19:35 LAMP for centos7.4/apr-1.
        阅读全文
        
摘要:1 [root@localhost sed]# sed -r '/^adm/{h;d};$G' passwd 2 root:x:0:0:root:/root:/bin/bash 3 bin:x:1:1:bin:/bin:/sbin/nologin 4 daemon:x:2:2:daemon:/sbi
        阅读全文
        
摘要:nginx批量分发脚本编写 [root@x112 vhost]# vim vhost.sh #!/bin/bash #describtion for install nginx virtualhost ListenPort=81 Num=1 ServerName=abc Count=$1 Path=
        阅读全文
        
摘要:一、nginx安装 下载nginx软件包 [root@x112 ~]# wget -c http://nginx.org/download/nginx-1.12.2.tar.gz [root@x112 ~]#tar -xf nginx-1.12.2.tar.gz [root@x112 ~]#cd n
        阅读全文
        
摘要:[root@x112 linshi]# cat count2.sh #!/bin/bash i=0 while [ $i -le 100 ] do #let sum=sum+i #sum=$((sum+i)) sum=$[sum+i] let i++ done echo "the count is 
        阅读全文
        
摘要:1 [root@localhost mv_test]# cat mv.sh 2 #!/bin/bash 3 4 DIR=/root/linshi/move 5 FILE=/root/linshi/test/mv 6 if [ -d $DIR ];then 7 rm -rf $DIR/* 8 fi 9
        阅读全文
        
摘要:1 [root@localhost array]# cat function_locate.sh 2 #!/bin/bash 3 if [ $# -ne 3 ];then 4 echo "usage: `basename $0` part1 part2 part3" 5 exit 6 fi 7 8 
        阅读全文
        
摘要:1 [root@localhost array]# cat for.sh 2 #!/bin/bash 3 for i 4 do 5 #echo abc 6 let sum+=$i 7 done 8 echo $sum 9 [root@localhost array]# sh for.sh 1 2 3
        阅读全文
        
摘要:1 [root@localhost array]# cat function_array.sh 2 #!/bin/bash 3 4 num=(2 3 4) 5 array() { 6 echo "all parameters: $*" 7 local newarray=(`echo $*`) #其中
        阅读全文
        
 
                    
                     
                    
                 
                    
                 
                
 
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号