小编Eri*_*rik的帖子

echo不会输出多行

我一直在尝试将命令输出到这样的文件:

echo `who | cut -d' ' -f1 | sort | uniq` > users.txt
Run Code Online (Sandbox Code Playgroud)

但内容users.txt是在一条线上.

但是,如果我只是执行这样的命令:

who | cut -d' ' -f1 | sort | uniq
Run Code Online (Sandbox Code Playgroud)

输出在多行上.

如果我使用echo输出这样的命令:

echo `who | cut -d' ' -f1 | sort | uniq`
Run Code Online (Sandbox Code Playgroud)

我得到1行的输出.

这里发生了什么?如何将此命令的输出写入具有多行的文件?

任何帮助都非常感谢.

编辑:

感谢一些评论,我意识到我不需要回声,我可以像这样输出:

who | cut -d' ' -f1 | sort | uniq > users.txt
Run Code Online (Sandbox Code Playgroud)

linux bash shell echo output

1
推荐指数
1
解决办法
464
查看次数

标签 统计

bash ×1

echo ×1

linux ×1

output ×1

shell ×1