bash的文件的内容附加到现有文件的底部 [英] bash append file contents to the bottom of existing file
问题描述
可能重复:结果
shell脚本将文本追加到每个文件?结果
<一href=\"http://stackoverflow.com/questions/6207573/how-to-append-output-to-the-end-of-text-file-in-shell-script\">How附加输出到shell脚本的文本文件的末尾?
我试图找出最好的方式插入API的细节到pre-现有的配置。我想过使用的sed
来API文本文件的内容插入到config.inc文件的底部。我已经开始了剧本,但它不工作,它抹文件。
I'm trying to work out the best way to insert api details into a pre-existing config. I thought about using sed
to insert the contents of the api text file to the bottom of the config.inc file. I've started the script but it doesn't work and it wipes the file.
#!/bin/bash
CONFIG=/home/user/config.inc
API=/home/user/api.txt
sed -e "\$a $API" > $CONFIG
我在做什么错了?
What am I doing wrong?
推荐答案
这应该工作:
cat "$API" >> "$CONFIG"
您需要使用&GT;&GT;
运营商将追加到一个文件中。与&GT重定向;
导致文件被覆盖。 (截断)。
You need to use the >>
operator to append to a file. Redirecting with >
causes the file to be overwritten. (truncated).
这篇关于bash的文件的内容附加到现有文件的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!