shell基础二十篇 一些笔记

shell基础二十篇

转自 http://bbs.chinaunix.net/thread-452942-1-1.html

 

 研讨:Bash 内建命令 read

(read命令更具体的说明见博客收藏的一篇:http://www.cnblogs.com/xiangzi888/archive/2012/03/27/2420084.html)

read -p "how old r u? " age
echo $age
read -p "some words? " -a words
echo ${words[*]}
read -p "Password: " -s passwd
echo $passwd
read -t 5 auth
echo $auth
read -n 1 key
read -dq -p "input something end with q: " menu
read -e file #在这试试命令历史和补齐功能

 

我认为read ?很好用,比echo "input:";read input...用简便!像这样:
read input?"input:"
echo $input

而且read a b c这样用也很实用:
echo -n "please year month day"
read a b c
echo $a $b $c

另外就是read读fd,比如常用的两个文件的拼接:
while read -u3 i && read -u4 j;do
echo $i $j
done 3<afile 4<bfile

 

sed '1,3d' quote.txt  删除1-3行。

sed '/Neave/d' quote.txt  删除所有包含Neave的行。

sed 's/splendid/SPLENDID/w sed.out' quote.txt    替换并将结果写到文件sed.out中。

 

posted @ 2015-07-15 13:51  IT由零开始  阅读(191)  评论(0编辑  收藏  举报