bash - 将代码附加到 block 时 sed 未终止 `s' 命令

标签 bash ubuntu sed

这是我要更改的文件。我想在 servers { 下添加一个条目。

eap-radius {

    # Section to specify multiple RADIUS servers.
    servers {

    }
}

这是我试过的

sed -i '/servers {/a\
server-a {
            accounting = yes
            secret = 123456
            address = 127.0.0.1
            auth_port = 1812
            acct_port = 1813
}
' /etc/strongswan.d/charon/eap-radius.conf

sed: -e expression #1, char 81: unterminated `s' command

最佳答案

我认为你需要转义新行:

sed '/servers {/a\
        server-a {\
            accounting = yes\
            secret = 123456\
            address = 127.0.0.1\
            auth_port = 1812\
            acct_port = 1813\
        }
' ./test.txt

结果是(我还标记了一点 server-a block ):

eap-radius {

    # Section to specify multiple RADIUS servers.
    servers {
        server-a {
            accounting = yes
            secret = 123456
            address = 127.0.0.1
            auth_port = 1812
            acct_port = 1813
        }

    }
}

在 Ubuntu 14.04.5 LTS、GNU bash 版本 4.3.11(1)-release 上测试

关于bash - 将代码附加到 block 时 sed 未终止 `s' 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47366311/

相关文章:

docker - 构建具有 "RUN apt-get update"的 Dockerfile 给我 "jailing process inside rootfs caused ' 权限被拒绝'”

linux - 使用 awk 或 sed 的特定数据格式化

linux - 打印包含 11 行的每个数据 block

linux - 如何在mailx命令中添加收件人姓名

linux - sed如何在第一行末尾添加带竖线的变量

php - shell_exec 不运行某些 shell 命令

bash - 比较日期的 Shell 脚本

python - CVLC 无法连接到 D-Bus session

Bash 循环遍历文件过早结束

bash - 如何找到当前目录下的可执行文件并找出它们的扩展名?