vagrant up 命令错误 'unexpected end of file /vagrant/provision/prep_server.sh'

Error 'unexpected end of file /vagrant/provision/prep_server.sh' by vagrant up command

我试过 vagrant up。 我在主机上的环境

Vagrant 得到框 bento/debian-8.6、设置端口、安装共享文件夹,然后返回错误

==> myvag: /vagrant/provision/prep_server.sh: line 2: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 4: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 10: $'\r': command not found
==> myvag: Updating Aptitude
==> myvag: /vagrant/provision/prep_server.sh: line 14: $'\r': command not found
==> myvag: Removing exim4
==> myvag: /vagrant/provision/prep_server.sh: line 20: $'\r': command not found
==> myvag: Performing an safe-upgrade
==> myvag: Reading changelogs...
==> myvag: Done with safe-upgrade
==> myvag: /vagrant/provision/prep_server.sh: line 25: $'\r': command not found
==> myvag: Adding dotdeb dependencies to apt sources if not there.
==> myvag: /vagrant/provision/prep_server.sh: line 27: $'\r': command not found
==> myvag: /vagrant/provision/prep_server.sh: line 30: $'\r': command not found
==> myvag: Adding dotdeb GPG Key
==> myvag: /vagrant/provision/prep_server.sh: line 42: syntax error: unexpected end of file

此文件的内容如下

#!/bin/bash

export DEBIAN_FRONTEND=noninteractive

############ Ultimately, this is a HACK: ###############
## Because of libssl and heartbleed, there are some
## debian propts that come up and destroy screw up
## Our provisioning scripts in salt and make the output
## really funny.

# Update our packages data
echo "Updating Aptitude"
sudo aptitude update > /dev/null

# exim4 is the stupid package causing the prompt to occur.
# It was just easier to remove it than automate the lib's
# Upgrade screen.
echo "Removing exim4"
sudo aptitude purge -y -q -f exim4 > /dev/null

echo "Performing an safe-upgrade"
# Do an upgrade of the existing stuff
sudo -E bash -c 'aptitude safe-upgrade -y -f > /dev/null'
echo "Done with safe-upgrade"

echo "Adding dotdeb dependencies to apt sources if not there."
grep -q -F 'packages.dotdeb.org' /etc/apt/sources.list ||
echo "deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list

echo "Adding dotdeb GPG Key"
if ! apt-key list | grep -q -F  'dotdeb'; then
    wget https://www.dotdeb.org/dotdeb.gpg
    apt-key add dotdeb.gpg
    rm dotdeb.gpg
else
    echo "Dotdeb GPG Key present"
fi

echo "Updating apt-get"
apt-get update

据我所知,它可能与结局有关 \r\n,但我该如何解决。

同时我的同事在 vagrant up 上没有问题,但他在主机上使用 Ubuntu。

您的文件包含 windows 编码的回车 return,这在 linux 世界中是不同的。

您的解决方案:

  1. 运行 你的文件通过 dos2unix 脚本 (http://dos2unix.sourceforge.net)

  2. windows 上最高级的编辑器(UltraEdit、Notepad++)允许您专门为 linux 保存文件格式(例如 UltraEdit 有 File/convert可选择转换为 linux)