Welcome 微信登录

首页 / 操作系统 / Linux / Shell脚本点滴

1. 获取脚本当前路径:FILE_DIR=`echo $(cd $(dirname $0); pwd)`2. shell整数计算可用expr,非整数计算可用awk内置函数实现:四舍五入:awk BEGIN"{printf("%d", 1.7+0.5)}"保留小数:awk BEGIN"{printf "%.2f ", 2/3}"3. (())while read linedo((lineNum++))done < inputfile4.  在文件中查找关键字时,用grep -c XXX 比grep XXX | wc -l 的效率要高,但是查找进程时,ps -ef | grep XXX | grep -v grep |wc -l 才是对的,因为要过滤掉grep进程5.  grep -A4 "#!/bin/bash" dir.sh   #-A4 代表显示前四行6. cut命令linux-0xvi:/opt/Program # echo abcdefghi | cut -b2-5bcdelinux-0xvi:/opt/Program # echo abcdefghi | cut -c2-5bcdelinux-0xvi:/opt/Program # echo abc:def:hij:kmn | cut -d: -f2-3def:hij7.linux捕获信号:linux-0xvi:/opt/Program # cat signal.sh#!/bin/bashfunction handle{echo "received a signal"}trap "handle" HUP INT QUIT TSTPsleep 58.用stty和dd实现暂停linux-0xvi:/opt/Program # cat press.sh#!/bin/shfunction char{settty=$(stty -g)stty rawstty -echodd if=/dev/tty bs=1 count=1 2> /dev/nullstty echostty -rawstty $settty}echo -n "press any key to continue..."input=`char`9. perl -e "print time"10. 一条命令建立目录树: mkdir -p test/{inc,src,help/{html,pdf,doc}}64位CentOS:持续集成之路——MavenShell脚本调试方法相关资讯      shell 
  • Linux入门学习:认识shell和bash  (03月25日)
  • SHELL中创建临时文件的方法  (07/22/2014 10:45:00)
  • shell技巧分享  (03/08/2014 07:15:33)
  • 使用shell进行数学运算  (04/14/2015 06:14:58)
  • Shell在大数据时代的魅力:从一道百  (07/21/2014 07:26:42)
  • shell用户个人配置文件  (10/30/2013 20:10:00)
本文评论 查看全部评论 (0)
表情: 姓名: 字数