假设我有一个名为myDirectory
的HDFS目录,其中包含可变数量的子目录,如下所示:
/tmp
|___mainDirectory
|___ subDirectory1
|___ subDirectory2
.
.
|___ subDirectoryN
如何将mainDirectory中每个子目录的路径捕获为bash变量?
例如,在上面的例子中,我最终得到N个bash变量,每个变量看起来像这样:
var_1=/tmp/mainDirectory/subDirectory1
var_2=/tmp/mainDirectory/subDirectory2
..etc
到目前为止,在执行hadoop fs -ls /tmp/mainDirectory
$hadoop fs -ls /tmp/mainDirectory | awk '{print $8}'
/tmp/mainDirectory/subDirectory1
/tmp/mainDirectory/subDirectory2
.
.
/tmp/mainDirectory/subDirectoryN
但是,我无法将各个目录路径捕获到单独的bash变量中。
非常感谢任何帮助。谢谢!
答案 0 :(得分:1)
如果你打算得到结果:
$hadoop fs -ls /tmp/mainDirectory | awk '{print $8}'
/tmp/mainDirectory/subDirectory1
/tmp/mainDirectory/subDirectory2
.
.
/tmp/mainDirectory/subDirectoryN
您可以使用命令将它们分配给bash变量
$ declare $(hadoop fs -ls /tmp/mainDirectory | awk '{print "var_"NR"="$8}')