【问题标题】:SED Command not working in Vagrant Init scriptSED 命令在 Vagrant Init 脚本中不起作用
【发布时间】:2016-09-06 17:37:33
【问题描述】:

我有一个 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'

我尝试过玩转义,但我尝试的没有任何效果。我哪里错了?

【问题讨论】:

  • 看来您的第一个 /w 被处理为对 ww\/html\"/DocumentRoot \"\/var\/www\/html\/web\"/ 文件的写入命令。这可以解释第一条错误消息。

标签: bash sed centos vagrant vagrantfile


【解决方案1】:

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

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

【讨论】:

  • 谢谢。有一个类似的问题无法通过更改标记来解决。 sudo sed -i '/<Directory "\/var\/www\/html">/,/<\/Directory>/{s/AllowOverride None/AllowOverride All/}' /etc/httpd/conf/httpd.conf 给出了相同的错误,但将 / 更改为 ~ 并不能解决问题。请问我需要在那里做什么?
  • @williamsdb,如果您已将/ 更改为~,则无需转义其他出现在PATH 上的/
  • 这个:sed: -e expression #1, char 60: expected newer version of sed
  • @williamsdb,sed 的版本是多少?使用:sed --version
  • GNU sed 版本 4.2.1
猜你喜欢
  • 1970-01-01
  • 2017-03-05
  • 2013-12-04
  • 2014-04-18
  • 2016-11-01
  • 2014-09-16
  • 2017-03-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多