bash - SED 命令在 Vagrant Init 脚本中不起作用

标签 bash sed centos vagrant vagrantfile

我有一个 sed 命令,它可以定制 httpd.conf 文件并在命令行中完美运行:

sudo sed -i 's/DocumentRoot \"\/var\/www\/html\"/DocumentRoot \"\/var\/www\/html\/web\"/' /etc/httpd/conf/httpd.conf

但是,当作为 config.vm.provision 的一部分包含在 Vagrant 初始化脚本中时,它会失败,如下所示:

default: sed: 
==> default: couldn't open file ww/html"/DocumentRoot "/var/www/html/web"/: No such file or directory
==> default: sed: -e expression #1, char 44: expected newer version of sed
==> default: sed: -e expression #1, char 43: unknown option to `s'

我尝试过转义,但我尝试过的都不起作用。我哪里错了?

最佳答案

sed 中,您可以更改 regex 替换 标记。在这里,我将 / 更改为 ~ 以使命令更加清晰。

sed -i 's~DocumentRoot "/var/www/html"~DocumentRoot "/var/www/html/web"~' file

关于bash - SED 命令在 Vagrant Init 脚本中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37160597/

相关文章:

regex - 使用sed、awk等中间点字符后分隔

linux - 我的 crontab 有问题吗?

linux - 获得大于 X 的 awk 结果

python - 对于格式错误的 python 代码,sed 中的 camelCase 到 snake_case

bash - 忽略第一个命令中的 $

linux - 在 Linux 中拆分有序文件

linux - linux centos修改根文件夹权限的方法

ubuntu - 使用 sed 删除行在 Ubuntu 中不起作用

bash - shell脚本: how to pass 2 parameters in for loop?

linux - 当开机时间超过30分钟时重新启动计算机