用途
读取行信息
语法
read [-r] a b c ....
描述
读取每行的信息,并以IFS为分割符,把分割出的字符串依次传给a b c .......
-r:原始读取,不做任何处理,不将行结尾处的反斜杠解释为续行字符
举例
apuser@bj61087pcu:~/works/my_document$ cat readchar.txt
ad 45 16
jhjgsdjg
sjakhjk 1564
asjkhl 156 1654 1687
apuser@bj61087pcu:~/works/my_document$ cat read0.sh
#!/bin/sh
if [ -f read0.txt ]
then
rm read0.txt
fi
touch read0.txt
while read pa pb pc
do
echo $pa >> read0.txt
done < ./readchar.txt
apuser@bj61087pcu:~/works/my_document$ cat read0.txt
ad
jhjgsdjg
sjakhjk
asjkhl
apuser@bj61087pcu:~/works/my_document$ vim read0.sh
apuser@bj61087pcu:~/works/my_document$
apuser@bj61087pcu:~/works/my_document$
apuser@bj61087pcu:~/works/my_document$ cat read0.sh
#!/bin/sh
if [ -f read0.txt ]
then
rm read0.txt
fi
touch read0.txt
while read pa pb pc
do
echo $pb >> read0.txt
done < ./readchar.txt
apuser@bj61087pcu:~/works/my_document$ ./read0.sh
apuser@bj61087pcu:~/works/my_document$ cat read0.txt
45
1564
156
apuser@bj61087pcu:~/works/my_document$