0

I have a Bash script that takes todays date as command line argument, calculates the previous day and creates a hive query to create a table at a certain location on hdfs. I can't seem to get the concatenation of strings right.

#!/usr/bin/env bash

echo $1
onedaybehind=`date -d "$1 - 1 days" +%Y-%m-%d`
echo $onedaybehind

hivequery="CREATE TABLE abc(id bigint, name string )
           ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'
           LOCATION 'hdfs://nameservice1/data/abc/"        
echo $hivequery
st = $hivequery$onedaybehind
echo $st

Both the variables onedaybehind and hivequery are printed properly but it cant identify the variable st. i tried using quotes and brackets too.

Ideally i want to generate the string :

CREATE TABLE abc( id bigint, name string)
        ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'
         LOCATION 'hdfs://nameservice1/data/abc/2015-11-15;'"  

(With a semicolon and single quote in the end). I run this program by : sh test.sh 2015=11-16.

Please help, not sure if its the casting date to string that is a problem but I can't get the concatenation right.

codeforester
  • 39,467
  • 16
  • 112
  • 140
user1189851
  • 4,861
  • 15
  • 47
  • 69

0 Answers0