'Loop through table name in Hive

I'm trying loop through table name and export the table schema as .csv file. Here is my shell script:

#!/bin/bash
## declare an array variable
declare -a array=("table1"
                  "table2")

# get length of an array
arraylength=${#array[@]}

# use for loop to read all values and indexes
for (( i=0; i<${arraylength}; i++ ));
do
  echo "index: $i, value: ${array[$i]}"
  hive -e $('DESCRIBE FORMATTED ${array[$i]') | sed 's/[\t]/,/g' > /tmp/${array[$i]}.csv
done

But I got this error:

test.sh: line 14: DESCRIBE FORMATTED ${array[$i]: command not found
Missing argument for option: e

Any suggestions?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source