[关闭]
@bornkiller 2014-11-20T23:42:49.000000Z 字数 2219 阅读 2412

linux shell script

linux


环境依赖

变量声明

  1. declare [-airx] variable
  2. -a: array
  3. -i: integer
  4. -r: readonly
  5. -x: env variable
  1. var[1]="snowy";
  2. var[2]="winter";
  3. var[3]="summer";
  4. echo ${var[1]};
  1. [root@localhost ~]# echo $test
  2. /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/root/bin
  3. [root@localhost ~]# echo ${test##*:}
  4. /root/bin
  5. [root@localhost ~]# echo ${test#*:}
  6. /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/root/bin
  7. [root@localhost ~]# echo ${test%%:*}
  8. /usr/lib64/qt-3.3/bin
  9. [root@localhost ~]# echo ${test%:*}
  10. /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/go/bin
  11. [root@localhost ~]#
  12. [root@localhost ~]# test=${test#*:}
  13. [root@localhost ~]# echo $test
  14. /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/root/bin
  15. [root@localhost ~]# echo ${test/sbin/bin}
  16. /usr/local/bin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/root/bin
  17. [root@localhost ~]# echo ${test//sbin/bin}
  18. /usr/local/bin:/usr/local/bin:/bin:/bin:/usr/bin:/usr/bin:/usr/local/go/bin:/root/bin
  19. //-变量未设置
  20. [root@localhost ~]# echo ${test-love}
  21. love
  22. //:-未设置或为空
  23. [root@localhost ~]# echo ${test:-love}
  24. love

历史命令

  1. history [n][-c]
  2. #n 最近N条命令
  3. #-c 清除内存命令记录
  4. history [-raw] [histfiles]
  5. !number
  6. #执行编号标记命令
  7. !!
  8. #执行上一条命令
  9. !command
  10. #执行command开头的命令

组合按键

+ ctrl + c //暂停命令执行
+ ctrl + u //删除整行命令

命令执行判断依据

type description
; 无相关性连续操作
cmd1&&cmd2 cmd1正确执行($?=0)cmd2执行
cmd1||cmd2 cmd1执行出错cmd2才开始执行

命令判断从左到右执行

管道命令

  1. cut -d 'divider' -f 'field'
  2. cut -c [range]
  3. [root@localhost ~]# echo $test
  4. /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/go/bin:/root/bin
  5. [root@localhost ~]# echo $test | cut -d ':' -f 3,4
  6. /usr/local/bin:/sbin
  7. # -d,-f配合使用单行截取
  8. # -c 格式化输出单行截取
  9. # cut命令用于单行截取,多空格相连数据处理吃力
  10. grep [-inv] 'string'
  11. # -i 不区分大小写
  12. # -n 输出行号
  13. # -v 取反
  14. sort [-Mnrutk] stdin
  15. # -u unique
  16. # -t 分隔符
  17. # -k key
  18. uniq [-ic]
  19. # -i insensitive
  20. # -c count
  21. wc [-lwm]
  22. # -l line number
  23. # -w word number
  24. # -m character number
  25. tee [-a] file
  26. # 保存数据流

gawk

Download link http://pan.baidu.com/s/1jG1fcdK.

  1. gzip -d -c gawk-4.1.1.tar.gz | tar -xvpf -
  2. cd gawk-4.1.1
  3. ./configure
  4. make

每一列内容不要有空格或者tab在内。

NPM

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注