【发布时间】:2011-10-16 07:36:24
【问题描述】:
我想将表格中的一些数据提取到 shell 脚本中的变量中。现在我做这样的事情:
export NAME=`mysql -NB -e "select name from user where id = $ID"`
export AGE=`mysql -NB -e "select age from user where id = $ID"`
export LOCATION=`mysql -NB -e "select location from user where id = $ID"`
这很好用,但我希望在一个查询中完成所有操作,例如:
select name, age, location from user where id = $ID
我尝试像这样使用“读取”:
mysql -NB -e "select name, age, location from user where id = $ID" | read NAME AGE LOCATION
echo $NAME
...但它没有像我预期的那样工作(“echo”行没有输出)。我错过了什么吗?
【问题讨论】: