简体   繁体   English

通过单行回显在Java中回显多行

[英]Echoing multiple lines in java through a single line of echo

I have a Java code like this: 我有这样的Java代码:

      "echo 'hello1' > abc.sh\n" +
      "echo 'hello2' >> abc.sh\n" +
      "echo 'hello3' >> abc.sh\n";

The first line opens the abc.sh shell file, and the next two lines appends the content (hello2 and hello3). 第一行打开abc.sh Shell文件,后两行追加内容(hello2和hello3)。 Is there anyway I can do it in a single echo command itself instead of using multiple lines? 无论如何,我可以在单个echo命令本身中完成它,而不用使用多行?

Thanks! 谢谢!

Echo accepts line feed without any issues .So you can, Echo接受换行没有任何问题。因此,

$ echo "test multiline
inuput to
my multiline file" > multi_file.dat

So add the line feed (\\n) within the echo command. 因此,在echo命令中添加换行符(\\n)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM