我想使用 bash 在文件中编写脚本,该脚本是自动生成的,假设我有一个名为 some.sh 的文件,其内容如下:
{
soemthings;
soemthings_other;
}
我想将脚本添加到 some.sh 变成这样
{
soemthings;
# the script
{
hello there
im the new script
and multilines
}
soemthings_other;
}
是否可以使用
sed
来执行此操作? ?
最佳答案
创建一个名为 script.tmp
的文件像这样:
# the script
{
hello there
im the new script
and multilines
}
然后用这个
sed
将其插入 some.sh
:sed -i.bak '/soemthings;/r script.tmp' some.sh
cat some.sh
{
soemthings;
# the script
{
hello there
im the new script
and multilines
}
soemthings_other;
}
关于bash - 在 block bash 脚本中写入多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35071683/