BBS.ChinaUnix.net
首页 | 新闻 | Linux | FreeBSD | AIX | Windows | 博客 | 论坛 | 存储 | 网络 | 人才 | Wiki | 资料 | 读书 | 手册 | 下载 | 空间 | 搜索
  免费注册 | 忘记密码 | 会员登录 | 搜索 | 帮助 



精彩推荐帖子 研讨:Bash 内建命令 read
首页 » 论坛 » Shell »  
[打印] [订阅] [收藏] [本帖文本页] [推荐此主题给朋友,立即获积分]
  本主题由 waker 于 2008-8-28 12:45 关闭 
r2007   帅哥 (呆子)
荣誉版主-精灵使
3楼楼长


CU奥运火炬传递手2008
荣誉版主  
CU编号: 115226
注册:2003-11-27
最后登录: 2009-07-04
帖子:4214
精华:4

可用积分:4557 (小富即安)
信誉积分:100
专家积分:0 (本版:0)
空间积分:3
推广积分:0

状态:...在线...

[个人空间] [短信] [博客]


1楼 发表于 2004-1-5 23:05 

这是在"man bash"中的一段

read [-ers] [-u fd] [-t timeout] [-a aname] [-p prompt] [-n nchars] [-d delim] [name ...]
    One  line  is  read  from  the  standard input, or from the file descriptor fd supplied as an argument to the -u option, and  the first word is assigned to the first name, the second word to the second name, and so on, with leftover words and their  intervening  separators  assigned  to the last name.  If there are fewer words read from the input stream than names, the remaining names are  assigned  empty  values.  The characters in IFS are used to split the line into words.  The backslash character (\)  may  be used  to  remove any special meaning for the next character read and for line continuation.  Options, if supplied, have the  following meanings:
    -a aname
    The words are assigned to sequential indices of the array variable aname, starting at 0.  aname is unset before any new  values  are  assigned.   Other  name  arguments  are ignored.
    -d delim
    The first character of delim is  used  to  terminate  the input line, rather than newline.
    -e     If the standard input is coming from a terminal, readline (see READLINE above) is used to obtain the line.
    -n nchars
    read returns after reading nchars characters rather  than waiting for a complete line of input.
    -p prompt
    Display prompt on standard error, without a trailing newline, before attempting to read any input.  The prompt is displayed only if input is coming from a terminal.
   -r     Backslash does not act as an escape character.  The backslash is considered to be part of the line.  In  particular,  a  backslash-newline pair may not be used as a line continuation.
   -s     Silent mode.  If input is coming from a terminal, characters are not echoed.
   -t timeout
   Cause  read  to time out and return failure if a complete line of input is not read within timeout  seconds.  This option  has  no  effect if read is not reading input from the terminal or a pipe.
    -u fd  Read input from file descriptor fd.

    If no names are supplied, the line read is assigned to the ariable  REPLY.   The  return  code  is zero, unless end-of-file is ncountered, read times out, or an invalid  file  descriptor  is supplied as the argument to -u.

经测试发现许多shell资料中没有介绍过的新内容,或许地球人都知道了^_^,不管怎样希望有兴趣的一起琢磨一下。
以下是我用来测试的代码,结果已经略去,请大家自行测试。

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 #在这试试命令历史和补齐功能

有兴趣的,别忘了跟贴^_^



您对本贴的看法:鲜花[0] 臭蛋[0]
bjgirl   美女
精灵使




CU编号: 60743
注册:2003-6-2
最后登录: 2006-08-29
帖子:4841
精华:7

可用积分:4833 (小富即安)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

来自:FreeSpace
状态:...保密...

[个人空间] [短信] [博客]


2楼 发表于 2004-1-5 23:41 

研讨:Bash 内建命令 read

bash的read选项比ksh的多两个 ,而且没有-t :(



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

/
bjgirl   美女
精灵使




CU编号: 60743
注册:2003-6-2
最后登录: 2006-08-29
帖子:4841
精华:7

可用积分:4833 (小富即安)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

来自:FreeSpace
状态:...保密...

[个人空间] [短信] [博客]


3楼 发表于 2004-1-5 23:46 

研讨:Bash 内建命令 read

我认为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

继续跟呀~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

/
c1l2d3   帅哥
大天使



CU编号: 30289
注册:2002-11-23
最后登录: 2007-09-13
帖子:1977
精华:6

可用积分:1765 (家境小康)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

来自:北大荒
状态:...离线...

[个人空间] [短信] [博客]


4楼 发表于 2004-1-5 23:46 

研讨:Bash 内建命令 read

偶机器里还没bash哩 :em23:



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________


bjgirl   美女
精灵使




CU编号: 60743
注册:2003-6-2
最后登录: 2006-08-29
帖子:4841
精华:7

可用积分:4833 (小富即安)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

来自:FreeSpace
状态:...保密...

[个人空间] [短信] [博客]


5楼 发表于 2004-1-5 23:48 

研讨:Bash 内建命令 read

[quote]原帖由 "c1l2d3"]偶机器里还没bash哩 :em23:[/quote 发表:

我的机器里面没有ZSH,;)



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

/
c1l2d3   帅哥
大天使



CU编号: 30289
注册:2002-11-23
最后登录: 2007-09-13
帖子:1977
精华:6

可用积分:1765 (家境小康)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

来自:北大荒
状态:...离线...

[个人空间] [短信] [博客]


6楼 发表于 2004-1-5 23:55 

研讨:Bash 内建命令 read

[quote]原帖由 "bjgirl"]我的机器里面没有ZSH,;)[/quote 发表:


ZSH啊!MM快发一个给我 :em11:

灌水的隐又犯了,向版主道歉。 :oops:



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________


bjgirl   美女
精灵使




CU编号: 60743
注册:2003-6-2
最后登录: 2006-08-29
帖子:4841
精华:7

可用积分:4833 (小富即安)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

来自:FreeSpace
状态:...保密...

[个人空间] [短信] [博客]


7楼 发表于 2004-1-6 00:10 

研讨:Bash 内建命令 read



QUOTE:
原帖由 "c1l2d3" 发表:


ZSH啊!MM快发一个给我 :em11:

灌水的隐又犯了,向版主道歉。 :oops:

到 rpmfind.net 上搜索吧~~,什么shell都有,就是没有石油shell ;)



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

/
網中人   帅哥
荣誉版主-法师



荣誉版主  
CU编号: 107641
注册:2003-10-28
最后登录: 2009-06-19
帖子:7973
精华:13

可用积分:7787 (富足长乐)
信誉积分:100
专家积分:54 (本版:0)
空间积分:0
推广积分:0

来自:Taiwan
状态:...离线...

[个人空间] [短信] [博客]


8楼 发表于 2004-1-6 03:02 

研讨:Bash 内建命令 read

加灌:

bjgirl MM 變臉了哦...  ^_^
嗯! 這張比上一張可愛多了... 簽名也更有詩意了!  ^_^



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

君子博學而日參省乎己,則知明而行無過矣。

:() { :|:& }; :      # <--- 這個別亂跑!好奇會死人的!
echo '十人|日一|十十o' | sed 's/.../&\n/g'   # <--- 跟你講就不聽,再跑這個好了...

bjgirl   美女
精灵使




CU编号: 60743
注册:2003-6-2
最后登录: 2006-08-29
帖子:4841
精华:7

可用积分:4833 (小富即安)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

来自:FreeSpace
状态:...保密...

[个人空间] [短信] [博客]


9楼 发表于 2004-1-6 03:06 

研讨:Bash 内建命令 read



QUOTE:
原帖由 "網中人" 发表:
加灌:

bjgirl MM 變臉了哦...  ^_^
嗯! 這張比上一張可愛多了... 簽名也更有詩意了!  ^_^

这回迷人不 :?: :!: :em09: :oops:



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

/
路人甲   帅哥
光明使者



CU编号: 27304
注册:2002-11-7
最后登录: 2009-04-22
帖子:876
精华:0

可用积分:360 (稍有积蓄)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

来自:江苏南京
状态:...离线...

[个人空间] [短信] [博客]


10楼 发表于 2004-1-6 08:43 

研讨:Bash 内建命令 read

[quote]原帖由 "bjgirl"]这回迷人不 :?: :!: :em09: :oops:[/quote 发表:


:em09:  :em09:  :em09:  :em09:



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

累了,
无语,
喝着啤酒,
发呆......

首页 » 论坛 » Shell »


 


Copyright © 2001-2009 ChinaUnix.net All Rights Reserved     联系我们:

感谢所有关心和支持过ChinaUnix的朋友们    转载本站内容请注明原作者名及出处

京ICP证041476号


清除 Cookies - ChinaUnix - Archiver - WAP - TOP

Processed in 0.067492 second(s), 5 queries , Gzip enabled