aix中read命令的用法

flysky0814發表於2007-11-14

$ 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(列印輸出的)

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11423276/viewspace-982362/,如需轉載,請註明出處,否則將追究法律責任。