错误';意外结束文件/vagrant/provision/prep#u server.sh';由流浪汉指挥

错误';意外结束文件/vagrant/provision/prep#u server.sh';由流浪汉指挥,vagrant,debian,windows-10,virtual-machine,virtualbox,Vagrant,Debian,Windows 10,Virtual Machine,Virtualbox,我试着做了一个流浪汉。 主机上的我的环境 微软视窗10 虚拟盒5.1.10 流浪汉1.8.6 Vagrant获得了boxbento/debian-8.6,设置了端口,安装了共享文件夹,之后返回了错误 ==> myvag: /vagrant/provision/prep_server.sh: line 2: $'\r': command not found ==> myvag: /vagrant/provision/prep_server.sh: line 4: $'\r': co

我试着做了一个流浪汉。 主机上的我的环境

  • 微软视窗10
  • 虚拟盒5.1.10
  • 流浪汉1.8.6
Vagrant获得了box
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编码的回车符,这在linux世界中是不同的

您的解决方案:

  • 通过dos2unix脚本()运行文件

  • windows上的大多数高级编辑器(UltraEdit,Notepad++)允许您保存专门针对linux的文件格式(例如UltraEdit具有file/convert,并带有针对linux的转换选项)


  • 你说的“rub file”是什么意思?我运行命令vagrant up,这个文件是自动创建的。这个文件不是由vagrant创建的。这是你自己的配置脚本。你需要确保它不是用Windows特定的回车编码的