Vagrant Provision sed命令返回错误

时间:2019-02-03 15:52:15

标签: sed vagrant vagrantfile

我正在尝试将外壳sed命令作为config.vm.provision的一部分

  config.vm.provision "shell", inline: <<-SHELL
    systemctl stop firewalld
    systemctl disable firewalld
    swapoff -a
    sed -i '/\/swapfile/s/^/#/g' /etc/fstab
  SHELL

基本上我想做的是注释/etc/fstab文件中的交换项。

但是我得到一个错误:

    master: Running: inline script
    master: sed: -e expression #1, char 18: unterminated `s' command
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

当我在盒子上运行时,sed命令运行得很好,但是当我将其作为Vagrantfile的一部分提供时却出错了。

有人知道为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

可以尝试吗?

$script = <<-SCRIPT
systemctl stop firewalld
systemctl disable firewalld
swapoff -a
sed -i '/\/swapfile/s/^/#/g' /etc/fstab
SCRIPT

Vagrant.configure("2") do |config|
  config.vm.provision "shell", inline: $script
end