我们如何在不使用io重定向的情况下通过单行命令将文本附加到文件中?
最佳答案
如果您不介意使用 sed那么,
$ cat test this is line 1 $ sed -i '$ a\this is line 2 without redirection' test $ cat test this is line 1 this is line 2 without redirection
由于文档可能有点长,一些解释:
-i
表示就地转换,因此所有更改都将发生在您指定的文件中$
用于指定最后一行a
表示在 \
只是用作分隔符https://stackoverflow.com/questions/4640011/