Ubuntu shell脚本:坏替换运行-hiveconf

时间:2016-10-13 18:59:05

标签: shell unix hive

  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 

这是我的.sh文件,其用法显示在函数用法()

每次运行shell脚本

时,我都会遇到此错误
test.sh: 14: test.sh: Bad substitution

1 个答案:

答案 0 :(得分:0)

你必须逃避最后两个$个字符。他们有许多不同的special meanings更改此行的第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}";

请注意两个\之前的$个字符。