简体   繁体   English

将输出存储到shell变量中

[英]Storing the output into shell variable

I wish to store the Output of the following command over my postgres database 我希望将以下命令的输出存储在我的postgres数据库中

sudo -u postgres -H -- psql -d firstdb -c"select count(col2) from table2;" sudo -u postgres -H-psql -d firstdb -c“从table2中选择count(col2);”

into a variable defined in shell. 放入外壳中定义的变量。 I saw this way somewhere- 我在某处这样看

abc=sudo -u postgres -H -- psql -d firstdb -c"select count(col2) from table2;" abc = sudo -u postgres -H-psql -d firstdb -c“从table2中选择count(col2);” echo abc 回声abc

but seems to be not working Is there any other way to store the output so as to apply cut query to fetch the value and check for the size of column?? 但是似乎不起作用,是否还有其他方法可以存储输出以便应用cut查询来获取值并检查列的大小?

You can do: 你可以做:

abc=$(svn://solace2/svn/vrs32/branches/feature/ipv6_support 2>&1)

and then do echo $abc to see the output. 然后执行echo $abc以查看输出。 Notice the 2>&1 at the end will redirect stderr to stdout before assigning stdout to the variable, meaning abc will contain error messages as well as regular messages. 请注意,最后的2>&1将在将stdout分配给变量之前将stderr重定向到stdout,这意味着abc将包含错误消息以及常规消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM