$ cat readtxt
ni hao ma
he ha a
$ vi readtest
"readtest" 5 lines, 89 characters
#!/bin/ksh
while read xx yy zz
do
printf "%s %s %sn" $xx $yy $zz
done
$ readtest
ni hao ma
he ha a
--------------------------------------------------------------------------
$ vi readtest
"readtest" 5 lines, 82 characters
#!/bin/ksh
while read xx yy
do
printf "%s %s " $yy $xx
done
$ readtest
hao ma ni ha a he
------------------------------------------------------------------------
$ vi readtest
"readtest" 5 lines, 81 characters
#!/bin/ksh
while read xx yy
do
printf "%s %sn" $yy $xx
done
$ readtest
hao ma
ni
ha a
he
变量一一对应,若给予的变量个数没有文件中域的个数多,则将最后的几个域全赋给最后一个变量.
--------------------------------------------------------------------------
$ read word1?"please enter:" word2
please enter:hello world
You have mail in /usr/spool/mail/oracle
$ echo $word1
hello
$ echo $word2
world
------------------------------------------------------------------------
$ (read; print "hello $REPLY")
word(我输入的)
hello word(打印输出的)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/11423276/viewspace-982362/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/11423276/viewspace-982362/