shell学习笔记
1、变量相加
total=$((total+cur))
$ a=10
$ b=5
$ c=$((${a}+${b}))
$ echo $c
a=20
b=30
let sum="$a+$b"
echo "$sum"
输出:50
--------------------------
[email protected]:~$ expr 6/3
6/3
[email protected]:~$ expr 6 / 3
2
-------------------expr有优先级 运算符左右需要空格
否则+号将当成普通符号
2、cur=`/usr/local/mysql/bin/mysql -uroot -pqazwsx -e"select count(*) from cloud_transcode" |awk 'NR>1
运行mysql取返回值,使用管道。。
3、单引号,双引号,反引号
单引号原样输出
反引号执行内容后输出
双引号和单引号差不多,但可以做变量的取值计算,可以记为双方通信,可以使用$
4、grep
grep 或查询
sh query_video_info_bat.sh | grep -E "GCID|Width=|Height|Result"
/usr/local/mysql/bin/mysql -uroot -psd-9898w -e"select TransGCID,TransCID,TransFileSize,TransSpecs from $table.transcode_result_$temp;"|awk 'NR>1' >>data/${temp}.txt
后台运行
nohup mp4transcodetoVS3.sh &
分割字符
${gcid:0:2}
分隔符 :
| awk -F ":" '{print $1}'`
scp -rp [email protected]:/filepath1 [email protected]t2:/filepath2
-p Preserves modification times, access times, and modes from the original file.
备份模式(修改时间、访问时间及modes)
-r Recursively copy entire directories.
递归地复制整个目录
截取字符串最后二位
gfs_path=$GFS_PREFIX"/"${gcid:0:2}"/"${gcid:${#gcid}-2}"/"$gcid
.echo string|rev|cut -c-2|rev
查看磁盘空间
df -h
用命令查询一个机器是32位还是64位 收藏
1.getconf LONG_BIT or getconf WORD_BIT
例如:
[[email protected] /]# getconf LONG_BIT
64
2.file command
例如:
[[email protected] /]# file /bin/ls
/bin/ls: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), stripped