Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 将参数从shell脚本传递到配置单元脚本_Bash_Hadoop_Hive - Fatal编程技术网

Bash 将参数从shell脚本传递到配置单元脚本

Bash 将参数从shell脚本传递到配置单元脚本,bash,hadoop,hive,Bash,Hadoop,Hive,我有一个问题可以分为两类: 我的要求是将参数从shell脚本传递到配置单元脚本。 或 在一个shell脚本中,我应该在配置单元语句中包含变量的值 我将用一个例子说明这两个方面: 1将参数从shell脚本传递到hiveQL-> My test Hive QL: select count(*) from demodb.demo_table limit ${hiveconf:num} 我的测试shell脚本: cnt=1 sh -c 'hive -hiveconf num=$cnt -f count

我有一个问题可以分为两类: 我的要求是将参数从shell脚本传递到配置单元脚本。 或 在一个shell脚本中,我应该在配置单元语句中包含变量的值

我将用一个例子说明这两个方面:

1将参数从shell脚本传递到hiveQL->

My test Hive QL:
select count(*) from demodb.demo_table limit ${hiveconf:num}
我的测试shell脚本:

cnt=1
sh -c 'hive -hiveconf num=$cnt -f countTable.hql'
所以基本上我想在HQL中包含'cnt'的值,这在本例中不会发生。我得到的错误是:

FAILED: ParseException line 2:0 mismatched input '<EOF>' expecting Number near 'limit' in limit clause
在上述两种情况下,我都无法传递参数值。有什么想法吗

PS:我知道把“限制”包含在计数中似乎很荒谬,但我已经重新表述了我实际遇到的问题。这项要求在通过辩论之前保持不变

有什么想法吗


提前感谢。

按以下方式设置变量:

#!/bin/bash
cnt=3
echo "Executing the hive query - starts"
hive -hiveconf num=$cnt -e ' set num; select * from demodb.demo_table limit ${hiveconf:num}'
echo "Executing the hive query - ends"
试试这个 cnt=1


如果将其放在名为hivetest.sh的文件中,然后使用sh hivetest.sh调用,则此操作有效:

您使用的是单引号而不是双引号。
对选项1使用双引号也很好。

hadoop@osboxes:~$export val=2

hadoop@osboxes:~$hive-e从bms.bms1中选择*,其中max_seq=$val


在第二种情况下,您可以执行echo并查看您得到的结果:echo“select count*”from demodab.demo_table limit$cnt”使用单引号抑制扩展。num=$cnt,如果您想使答案更通用,则可以传递不仅仅是数字的内容,还可能包含空格、全局字符等。感谢sras,这非常完美。我从未从命令行为配置单元使用过多个选项。完全同意查尔斯的观点;单引号抑制信息。更准确地说,我们可以使用hivevar名称空间而不是hiveconf名称空间。但是,这两种方法都适用于您的查询。
#!/bin/bash
cnt=3
echo "Executing the hive query - starts"
hive -hiveconf num=$cnt -e ' set num; select * from demodb.demo_table limit ${hiveconf:num}'
echo "Executing the hive query - ends"
hive -hiveconf number=$cnt select * from demodb.demo_table limit ${hiveconf:number}
cnt=2
hive -e "select * from demodb.demo_table limit $cnt"
vi test.sh
#########
export val=2
hive -e "select * from bms.bms1 where max_seq=$val";
#####################