Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4745285
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类:

2008-11-04 19:38:06

shell获取输入的时候,一般是需要回车才处理的,那怎么实现Press any key to continue...呢?
改改终端属性了哦^_^
zj@zj:~/Script/cushell/08.11.04$ cat getch.sh
#!/bin/bash


get_char()
{
        SAVEDSTTY=`stty -g`
        stty -echo
        stty raw
        dd if=/dev/tty bs=1 count=1 2> /dev/null
        stty -raw
        stty echo
        stty $SAVEDSTTY
}

echo "Press any key to continue..."
char=`get_char`
zj@zj:~/Script/cushell/08.11.04$ ./getch.sh
Press any key to continue...

难得再开篇了,在放两个小脚本
计算某年某月的天数
zj@zj:~/Script/cushell/08.11.04$ cal 09 2008 | sed '1,2d' | xargs | awk '{print NF}'
30
多个空行替换为一个
awk -v i=0 '{while($0 ~ /^$/){i++;getline};if(i>1){i=0;printf("\n%s\n",$0)}else print $0}' urfile
思路一样你也实现任意多个空行的删除
如2+空行替换为2,<=2空行不变.思路一码事,自己琢磨.

阅读(908) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-11-05 16:07:42

多个空行替换为一个 sed '/^$/{ N /^\n$/D }' filename