Linux 脚本收集

括号的使用说明

参考:Double parenthesis with and without dollar

  • $(…) means execute the command in the parens and return its stdout.
$ echo "The current date is $(date)"
The current date is Mon Jul  6 14:27:59 PDT 2015
  • (…) means run the commands listed in the parens in a subshell. Example:
$ a=1; (a=2; echo "inside: a=$a"); echo "outside: a=$a"
inside: a=2
outside: a=1
  • $((…)) means perform arithmetic and return the result of the calculation. Example:
$ a=$((2+3)); echo "a=$a"
a=5
  • ((…)) means perform arithmetic, possibly changing the values of shell variables, but don’t return its result. Example:
$ ((a=2+3)); echo "a=$a"
a=5
  • ${…} means return the value of the shell variable named in the braces. Example:
$ echo ${SHELL}
/bin/bash
  • {…} means execute the commands in the braces as a group. Example:
$ false || { echo "We failed"; exit 1; }
We failed

有用脚本收集

文件读取

读取文件目录的所有文件,按行读取每个文件,判断行文字是否包含特定字符串;如果包含,通过特殊字符来split并输出想要的值。

#!/bin/sh
for filename in /home/okchem/mysqlbackup/*.sql; do
    while IFS= read line
    do
        # display $line or do somthing with $line
        if [[ $line == *"/ocf/"* ]]; then
            SUBSTRING=$(echo $line| cut -d'`' -f 2) # 用'`'来拆分,输出数组第二个
            echo $SUBSTRING
        fi
    done <"${filename}.sql"
done
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值