Chinaunix
标题:
Linux中的read问题请教
[打印本页]
作者:
lu.qinyuan
时间:
2004-05-31 12:46
标题:
Linux中的read问题请教
请问以下脚本为什么输出是空?
echo "hello" |read aa
echo $aa
在其它的UNIX操作系统上是可以输出结果hello的,请问应该怎么写才能给多个变量附值?例如
echo "test1 test2" |read a1 a2
作者:
kkng09
时间:
2004-05-31 12:59
标题:
Linux中的read问题请教
# echo "hello"|read aa
# echo $aa
# echo "hello"|(read aa;echo $aa)
hello
因為用"|"時, shell 會fork一個sub shell. ,在這個sub shell中,這時$aa= hello,
但sub shell完了後, main shell 的aa 不會改變,所以是空.
# cat data
test1 test2
# while read a1 a2;do echo "$a1->$a2";done <data
test1->test2
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2