Vagrantfile 中的 shell 脚本忽略注释

问题描述 投票:0回答:1

我的流浪文件

config.vm.provision "shell", inline:
  <<-SHELL
    BoxName="crbienes-test"

    echo -e $BPurple"Provisioning $BoxName..."

    #export DEBIAN_FRONTEND=noninteractive
    #apt-get install -y phpmyadmin
    #echo "\nInclude /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf

...给我一个错误

 crbienes-test: /tmp/vagrant-shell: line 80: Include: command not found
    crbienes-test: /tmp/vagrant-shell: line 95: syntax error near unexpected token `}'
    crbienes-test: /tmp/vagrant-shell: line 95: `       }'
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.

...在注释行

    #echo "\nInclude /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf

我不明白为什么它要执行注释行!

取消注释 echo 行即可解决问题。

vagrantfile
1个回答
0
投票

感谢 JK 对我发布的问题的巧妙纠正,我现在看到了问题所在。是的,如果我将问题改写为“为什么它执行注释行?”

#echo "\nInclude /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf

我可以看到 echo 不是带有 -e 选项的用户,因此 创建一个新行并尝试执行 Include... 行。

我仍然不明白为什么这一行首先被执行并且没有被哈希#注释忽略。

另外,如果我在后面插入一个空格 一切正常,注释行未执行。对我来说很神秘。

© www.soinside.com 2019 - 2024. All rights reserved.