how to print error in shell script while executing a vertica query?

Viewed 163

I want to print the error in assigned variable

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

You need redirect stderr to stdout with 2>&1, then you can get the error if the command have error:

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