简体   繁体   English

如何在bash脚本中将包含“ <>”的一个文件附加到另一个文件

[英]How to append one file that includes '< >' to another in bash script

Is there a way to append one file to another in a bash script without it complaining about the < > characters? 有没有一种方法可以在bash脚本中将一个文件追加到另一个文件而又不会抱怨< >字符? I'm trying to append a file that contains some xml to another but it keeps throwing a 我正在尝试将包含一些xml的文件追加到另一个文件,但它会不断抛出

syntax error near unexpected token 'newline'

'<myTag>'

The operation is simply myFile.txt >> otherFile.xml 该操作仅是myFile.txt >> otherFile.xml

I know they're placeholder characters but I haven't been able to turn up any results on making them get interpreted as literals 我知道它们是占位符,但是我无法将它们解释为原义的任何结果

You need to use cat : 您需要使用cat

cat myfile.txt >>otherFile.xml

Otherwise, you're trying to run myfile.txt as an executable; 否则,您尝试将myfile.txt作为可执行文件运行; the problem has nothing to do with the arrow-bracket characters embedded within the file's contents. 该问题与文件内容中嵌入的箭头括号字符无关。


By the way -- XML documents can only legally contain a single root, and are not allowed to have content outside of that root, so your new file probably isn't valid XML. 顺便说一句-XML文档只能合法地包含一个根目录,并且不允许在该根目录之外包含内容,因此您的新文件可能不是有效的XML。

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

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