ambitiousdev111 ambitiousdev111 - 1 month ago 17
Bash Question

Ubuntu shell scripting : Bad Substitution running -hiveconf

file_path="$1"
db_name="$2"
table_name="$3"
partition_name="$4"
usage(){
echo "you have used the command in a wrong manner "
echo "USAGE : sh LOAD_DATA.sh <<filepath>> <<db_name>> <<table_name>> <<partition_name_optional>> "
}
executeLoadQuery(){
# hive -hiveconf table_name=$4 -hiveconf file_path=$2 -hiveconf db_name=$3 -e "select * from ${hiveconf:db_name}.${hiveconf:table_name}; " ;
echo dont See me
}
testfunc(){
hive -hiveconf table_name="$3" -hiveconf db_name="$2" -e "LOAD data local inpath 'India1.txt' into table ${hiveconf.db_name}.${hiveconf.table_name}";
}
# $2 this will return true if the variable have a value
if [ ! $1 ]
then
usage
elif [ ! $2 ]
then
usage
else
echo "LODADING DATA"`enter code here`
testfunc
fi


THIS IS MY .sh file whose usage is shown in the function usage()

I am facing this error every time i run the shell script

test.sh: 14: test.sh: Bad substitution

Answer

You have to escape the two last $ characters. They have many different special meanings Change the line 14 for this one:

hive -hiveconf table_name="$3" -hiveconf db_name="$2" -e 
"LOAD data local inpath 'India1.txt' into table \${hiveconf.db_name}.\${hiveconf.table_name}";

Note the \ characters preceding the two $.