Abhishek
Abhishek

Reputation: 11

How to pass variable in hive query reading from file as table name

I am writing shell script which will read a table name from a file, and pass table name to hive query.

But i assume $ not recognized in hive.

Any idea how can I pass the variable in hive query?

Error : can not recognize input near $i

#!/bin/bash

#Input file
ifile="/tmp/table.txt" 

if [[ -f "$ifile" ]]
then
  while IFS= read -r i
    hive -e "show create table $i"
  done <"$ifile"
fi

$cat table.txt

office.empoyee
office.department
office.floor

Upvotes: 0

Views: 450

Answers (1)

suspectus
suspectus

Reputation: 17268

I think all that is missing here is the do after the while line:

if [[ -f "$ifile" ]]
then
  while IFS= read -r i
  do
    hive -e "show create table ${i}"
  done <"$ifile"
fi

Upvotes: 3

Related Questions