- 论坛徽章:
- 0
|
在bash下就输出一个空行
$echo "hello" | read var;
$echo $var;
$
就如beginner-bj 所说的在 bash下应该是subshell的方式
echo "hello" | (read var; echo $var)
是完美运行的,不过这里给的var也是subshell中的变量,外面还是无法调用
一般我们在aix下操作db2很多用到
db2 "select count(*),'num' from tablename" | grep -i num | read count other;
然后就直接可以使用$count来做一些操作了,现在在bash下代码就不通用了
假如用下面语句
db2 "select count(*), 'num' from test" | grep -i num | (read var other; echo $var); #输出8
这个8 如何赋值给一个变量呢?
-------------------
寂寞烈火 的方法可以实现值输出到变量
$read a b< <(echo "hello world");
$echo $a;
hello
$echo $b;
world
$read var other < <(echo "hello world"| grep -i world)
$echo $var;
hello
$echo $other;
world
但
$db2 "select count(*),'num' from test" | grep -i num;
8 num
$read count other < <(db2 "select count(*),'num' from test" | grep -i num)
$echo $count
$echo $other
$
都是输出空行,这个是为什么呢。。。还有烈火的这种用法好像很少看到,能具体解释下么,谢谢哈~~~
[ 本帖最后由 kenshinsee 于 2009-2-11 21:47 编辑 ] |
|