0
  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

1 Answers1

0

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 $.

Community
  • 1
  • 1
Jaime Caffarel
  • 2,401
  • 4
  • 30
  • 42
  • Hey thanks !!! it worked .. can you tell me where can i read about this .. why this is done??? – ambitiousdev111 Oct 13 '16 at 20:04
  • You're welcome :-) If you put a $ sign in the script, the interpreter will try to "do something" with that (for instance, get the first argument with `$1`). But in your script, you don't want that to happen. You just want to pass the string `${hiveconf...` "as is" to the hive script that you're calling. That's why you have to put an escape character \ before the dollar. That way, the interpreter won't try to use it. – Jaime Caffarel Oct 13 '16 at 20:16