14.shell脚本学习

简单的执行跟踪,会使得Shell显示每个被执行到的命令
sh -x delete.sh

查找与替换
grep
sed -i "s/t_rs_customer/t_rs_customer_bak/g" t_rs_customer_bak.sql 

使用cut选定字段
cut -d : -f 1,5 /etc/passwd
cut -d : -f 6 /etc/passwd

使用awk重新编排字段
默认一空白分隔字段
awk '{print $1}' delete.sh
awk '{print $1,$3}' delete.sh
设置字段分隔符
awk -F : '{print $1,$3}' /etc/passwd

计算行数、字数以及字符数
wc -l,wc -w,wc -c

if-elif-else-fi语句
if pipeline
   [pipeline ... ]
then
   statements-if-true-1
[ elif pipeline
   [pipeline ... ]
then
   statements-if-true-2
]
[ else
   statements-if-all-else-fails
]
fi

case语句
case var in
exp-1) 命令体1 ;;
exp-2) 命令体2 ;;
...
*)    命令体 ;;
esac

for循环
for i in {1..10}
do
   echo $i
done
i=1
while(($i<100))
do
    if(($i%4==0))
    then
        echo $i
    fi
    i=$(($i+1))
done

函数是指一段单独的程序代码,用以执行一些定义完整的单项工作

猜你喜欢

转载自www.cnblogs.com/allenhu320/p/11284552.html