我试图在 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/