bash bash脚本将字符串附加到同一目录中的多个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3673102/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bash script to append string to multiple files in same directory
提问by James Nine
Is there a way to write a BASH script that will append a string to every file in a directory?
有没有办法编写一个 BASH 脚本,将一个字符串附加到目录中的每个文件?
e.g., I want to append the string "test" to every .html file in the current working directory I'm in; something like:
例如,我想将字符串“test”附加到当前工作目录中的每个 .html 文件中;就像是:
echo "test" >> *.html
But of course this doesn't work.
但这当然行不通。
回答by James Nine
Nevermind, I figured it out.
没关系,我想通了。
#!/bin/sh
for f in *.html ; do
echo "test" >> $f
done
回答by ghostdog74
sed -i.bak '$a append' *.html

