简体   繁体   English

Ubuntu Shell脚本:运行-hiveconf的错误替换

[英]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() 这是我的.sh文件,其用法显示在函数usage()中

I am facing this error every time i run the shell script 每次我运行shell脚本时,我都会遇到此错误

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

You have to escape the two last $ characters. 您必须转义最后两个$字符。 They have many different special meanings Change the line 14 for this one: 它们具有许多不同的特殊含义 。为此更改第14行:

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 $ . 注意两个$前面的\\字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM