linux - Bash shell : Appending a newline after each input in a *. txt 文件

标签 linux bash shell

我试图在 bash 文本文件中保存从 1 到 10 的数字列表,每个数字占一行。

这是我使用的代码:

echo "1" >> test.txt
echo >> test.txt
echo "2" >> test.txt

当我用 cat test.txt 调用我的文件时,它会打印出所需的数字:

=> 输出:

1

2 

等...

但是当我在 bash 之外打开 .txt 文件时,信息保存为:12345678910

最佳答案

这就是你想要的

for i in `seq 1 10`; do echo $i >> test.txt; done

但相信 cat 而不是“Windows 记事本”并切换到 Notepad++、Atom、Sublime 等。

关于linux - Bash shell : Appending a newline after each input in a *. txt 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42683783/

相关文章:

c - 像 "bpf_map_update_elem"这样的bps API map 助手的详细过程是什么?

linux - BASH:测试字符串是否有效

linux - 将每 n 行转置为一行

linux - 是否所有命令 shell 脚本都有一个通用名称?

arrays - bash 中关联数组名称的数组

linux - 多个站点的 DIG 查询时间平均速度

bash - 如何从新终端中的程序获取返回码? (巴什 "Inception")

linux - 在 Bash 脚本中比较字符串时找不到命令错误 (stderr)

linux - 在 bash 脚本中使用 mv 丢失文件

c++ - Unix 自定义 shell 中的 chdir