0

我想解压缩几个文件并将其合并为 bash 中的一个变量。

例如:有几个文本文件。

one=text1.gz
two=text2.gz
three=text3.gz

我想将它们合并成一个变量

variable=(zcat $one $two $three)

所以

$variable=($one)+($two)+($three)

我怎样才能做到这一点?

4

1 回答 1

0

您的 bash 语法不正确。

要将命令的结果分配给变量,您需要使用$(...)

variable=$(zcat "$one" "$two" "$three")

根据您要对这些文件的内容执行的操作,这可能不是最好的方法。

您可能希望使用重定向将文件连接到另一个文件:

zcat "$one" "$two" "$three" > combined_file

然后使用combine_file.

或者直接使用 pipe 进一步处理命令|

zcat "$one" "$two" "$three" | my_command

my_command可能在哪里sedawk等等...

于 2018-09-28T06:35:16.803 回答