- 论坛徽章:
- 0
|
那就是说管道后的属于subshell,赋值的也是subshell中的变量,所有只有在subshell中输出,在父shell中赋值才行。
[db2inst1@hong Hong]$ var=`(db2 connect to db_1;db2 "select count(*),'yyyyy' from test")| grep -i yyyyy| (read count tmp;echo $count)`
[db2inst1@hong Hong]$ echo $var
8
[db2inst1@hong Hong]$
还有一个问题
如果我dbconnect和select不用括号括起来
[db2inst1@hong Hong]$ var=`db2 connect to db_1;db2 "select count(*),'yyyyy' from test"| grep -i yyyyy`
[db2inst1@hong Hong]$ echo $var
Database Connection Information Database server = DB2/LINUX 9.5.0 SQL authorization ID = DB2INST1 Local database alias = DB_1 8 yyyyy
[db2inst1@hong Hong]$
为什么var不是8 yyyyy 呢?
就是说为什么
db2 connect to db_1;db2 "select count(*),'yyyyy' from test" 通过管道传给subshell的不是select的结果,而是连dbconnect的信息都传过去的呢?
而
用括号后(db2 connect to db_1;db2 "select count(*),'yyyyy' from test" )传到后面的只是select的结果呢? |
|