print multiple lines in shell - improving readability in provisioning a Vagrantfile print multiple lines in shell - improving readability in provisioning a Vagrantfile nginx nginx

print multiple lines in shell - improving readability in provisioning a Vagrantfile


Assuming that there is Bash on your guest machine, you could try and use nested bash here documents. There is no guarantee that will work with Vagrantfile but it's worth a shot anyway.

config.vm.provision "shell", inline: <<-SHELL    sudo /bin/bash << 'SCRIPT'        rm /etc/nginx/sites-enabled/default;        cat << 'EOF' >> /etc/nginx/sites-enabled/default            %s\n            server {                root /home/vagrant/web;                index index.php index.html index.htm;                location / {                    try_files $uri $uri/ /index.php?$args ;                }                location ~ \.php$ {                    fastcgi_split_path_info ^(.+\.php)(/.+)$;                    fastcgi_pass unix:/var/run/php5-fpm.sock;                    fastcgi_index index.php;                    include fastcgi_params;                }            }EOF        service nginx startSCRIPTSHELL

Note that EOF, SCRIPT and SHELL must be placed in the very beginning of the line. There must not be any tabs or whitespaces in front of these words.