首页 > 解决方案 > 执行vertica查询时如何在shell脚本中打印错误?

问题描述

我想在分配的变量中打印错误

#!/bin/bash
a=$(vertica copy query) # if i got error here 
echo $a

标签: linuxshellvertica

解决方案


您需要重定向stderrstdoutwith 2>&1,然后如果命令有错误,您会得到错误:

#!/bin/bash
a=$(vertica copy query 2>&1) # if i got error here 
echo $a

推荐阅读