在shell中访问hiveconf变量

时间:2019-06-05 00:57:30

标签: shell hive hiveql

我想知道是否可以通过hive在shell中访问hiveconf变量。

例如:

set hivevar:DIR='scripts';

如果我直接输入:    !sh ls -l scripts

将打印该目录中的输出。

但是,!sh ls -l ${DIR}导致

ls: cannot access ${DIR}: No such file or directory

我怀疑这是因为该变量是一个蜂巢变量,并且当您运行!sh命令时,它无法识别${}语法。可以在hql脚本中定义一个变量,然后在!命令中使用它吗?

1 个答案:

答案 0 :(得分:0)

工作正常。从变量中删除单引号。也不要在sh之后写!

让我们在其中创建目录和文件

$ mkdir scripts
$ touch ./scripts/test.txt
$ ls ./scripts
test.txt

现在运行Hive,定义变量并运行ls

hive> set hivevar:DIR=scripts;
hive> ! ls ${hivevar:DIR};
test.txt

让我们在Hive中删除目录(使用! rm -r),然后尝试再次列出该目录:

hive> ! rm -r ${hivevar:DIR};
hive> ! ls ${hivevar:DIR};
ls: cannot access scripts: No such file or directory
Command failed with exit code = 2

如您所见,一切正常。

详细了解syntax

相关问题