linux - 执行vertica查询时如何在shell脚本中打印错误?
问题描述
我想在分配的变量中打印错误
#!/bin/bash
a=$(vertica copy query) # if i got error here
echo $a
解决方案
您需要重定向stderr
到stdout
with 2>&1
,然后如果命令有错误,您会得到错误:
#!/bin/bash
a=$(vertica copy query 2>&1) # if i got error here
echo $a
推荐阅读
- python - 为什么 Go 的 LookupAddr 以句号结尾?
- c# - NuGet 包引用导致项目中出现新文件夹
- r - 将特定文件从一个现有目录复制并粘贴到另一个现有目录
- daemon - 将超集作为服务运行
- jquery - AJAX 不解析 jsonp 响应
- sql - 按从上个月到本月的前 N 个变化过滤
- c# - VSTS 负载测试 - 如何动态读取当前运行的负载测试文件的运行设置
- javascript - Electron:如何在另一个文件中引用全局 BrowserWindow 对象?
- google-apps-script - G Suite 开发者中心执行清单?
- html - 如何在元素上使用 nowrap 水平滚动表格而不溢出到下一列?