質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
bash

bash(Bourne-again-Shell)は sh(Bourne Shell)のインプリメンテーションに様々な機能が追加されたシェルです。LinuxやMac OS XではBashはデフォルトで導入されています。

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

VirtualBox

VirtualBoxは、現在米オラクル社が開発している、 x86仮想化ソフトウェア・パッケージの一つです。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

1111閲覧

仮想環境起動時に-bash: eval: line 33: シンタックス エラー: 期待してないファイルの終了と表示される

luke04

総合スコア7

bash

bash(Bourne-again-Shell)は sh(Bourne Shell)のインプリメンテーションに様々な機能が追加されたシェルです。LinuxやMac OS XではBashはデフォルトで導入されています。

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

VirtualBox

VirtualBoxは、現在米オラクル社が開発している、 x86仮想化ソフトウェア・パッケージの一つです。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/03/22 11:51

編集2022/01/12 10:55

問題の概要

VagrantでVirtualBoxの仮想環境を立ち上げた際、以下のように表示されます。

Vagrant

1-bash: eval: line 33: シンタックス エラー: 期待してないファイルの終了 2export PATH="/home/vagrant/.pyenv/shims:${PATH}" 3export PYENV_SHELL=bash 4source '/home/vagrant/.pyenv/libexec/../completions/pyenv.bash' 5command pyenv rehash 2>/dev/null 6pyenv() { 7 local command 8 command="${1:-}" 9 if [ "$#" -gt 0 ]; then 10 shift 11 fi 12 13 case "$command" in 14 activate|deactivate|rehash|shell) 15 eval "$(pyenv "sh-$command" "$@")";; 16 *) 17 command pyenv "$command" "$@";; 18 esac 19} 20

問題が起こるようになったきっかけ

ローカル開発環境で機械学習を目的にPythonの学習を始めるため、以下のサイトを参考に環境を構築しようとした。
Vagrant + CentOS + pyenv + anaconda でホストOSから jupyter notebookを使う
すでにVirtualBoxやVagrantのインストール等はドットインストールを参考に完了させていたため、サイトの「pyenvとAnacondaのインストール」のところから構築を開始した。
二度登場する

Vagrant

1$ source ~/.bash_profile

の部分で同様の期待していないファイルの終了とのエラーコードが出ましたが、その後の工程に影響を与えないようだったので、無視して進めてしまった。
その後仮想環境を再起動する際に、Vagrantでのログイン時に上のエラーが表示されるようになった。

参考

自分でも調べたところ、全く同じ状況とみられる質問がありました。
-bash: eval: line 33: シンタックス エラー: 期待してないファイルの終了 を解決したい
しかし解決したかどうかが不明で解決法が不明だったため、自分からも質問させていただきました。

参考としてVagrantFileも以下に示します。自分は初心者で、情報不足等あるかもしれませんがどうかご回答よろしくお願いします。

Vagrantfile

1# -*- mode: ruby -*- 2# vi: set ft=ruby : 3 4# All Vagrant configuration is done below. The "2" in Vagrant.configure 5# configures the configuration version (we support older styles for 6# backwards compatibility). Please don't change it unless you know what 7# you're doing. 8Vagrant.configure("2") do |config| 9 # The most common configuration options are documented and commented below. 10 # For a complete reference, please see the online documentation at 11 # https://docs.vagrantup.com. 12 13 # Every Vagrant development environment requires a box. You can search for 14 # boxes at https://vagrantcloud.com/search. 15 config.vm.box = "bento/centos-6.8" 16 17 # Disable automatic box update checking. If you disable this, then 18 # boxes will only be checked for updates when the user runs 19 # `vagrant box outdated`. This is not recommended. 20 # config.vm.box_check_update = false 21 22 # Create a forwarded port mapping which allows access to a specific port 23 # within the machine from a port on the host machine. In the example below, 24 # accessing "localhost:8080" will access port 80 on the guest machine. 25 # NOTE: This will enable public access to the opened port 26 # config.vm.network "forwarded_port", guest: 80, host: 8080 27 28 # Create a forwarded port mapping which allows access to a specific port 29 # within the machine from a port on the host machine and only allow access 30 # via 127.0.0.1 to disable public access 31 # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" 32 33 # Create a private network, which allows host-only access to the machine 34 # using a specific IP. 35 config.vm.network "private_network", ip: "192.168.33.10" 36 37 # Create a public network, which generally matched to bridged network. 38 # Bridged networks make the machine appear as another physical device on 39 # your network. 40 # config.vm.network "public_network" 41 42 # Share an additional folder to the guest VM. The first argument is 43 # the path on the host to the actual folder. The second argument is 44 # the path on the guest to mount the folder. And the optional third 45 # argument is a set of non-required options. 46 # config.vm.synced_folder "../data", "/vagrant_data" 47 48 # Provider-specific configuration so you can fine-tune various 49 # backing providers for Vagrant. These expose provider-specific options. 50 # Example for VirtualBox: 51 # 52 # config.vm.provider "virtualbox" do |vb| 53 # # Display the VirtualBox GUI when booting the machine 54 # vb.gui = true 55 # 56 # # Customize the amount of memory on the VM: 57 # vb.memory = "1024" 58 # end 59 # 60 # View the documentation for the provider you are using for more 61 # information on available options. 62 63 # Enable provisioning with a shell script. Additional provisioners such as 64 # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the 65 # documentation for more information about their specific syntax and use. 66 # config.vm.provision "shell", inline: <<-SHELL 67 # apt-get update 68 # apt-get install -y apache2 69 # SHELL 70end 71

追記

原因と考えられる.bash_profileを見て各行間にechoで文字列を表示させて問題とみられる行を発見しました。2つのexport文が1行に書いてあり、改行したところエラーメッセージは出なくなりました。しかし、相変わらず同じコードが表示されます
これは直ったと考えていいでしょうか。
また、下の4行目~のコードはどこのファイルのコードなのでしょう?

Vagrant

1login as: vagrant 2vagrant@192.168.33.10's password: 3Last login: Tue Mar 24 05:47:45 2020 from 10.0.2.2 4export PATH="/home/vagrant/.pyenv/shims:${PATH}" 5export PYENV_SHELL=bash 6source '/home/vagrant/.pyenv/libexec/../completions/pyenv.bash' 7command pyenv rehash 2>/dev/null 8pyenv() { 9 local command 10 command="${1:-}" 11 if [ "$#" -gt 0 ]; then 12 shift 13 fi 14 15 case "$command" in 16 activate|deactivate|rehash|shell) 17 eval "$(pyenv "sh-$command" "$@")";; 18 *) 19 command pyenv "$command" "$@";; 20 esac 21} 22(anaconda3-2019.10) [vagrant@localhost ~]$

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

こういうエラーはたいていカッコとかブロックの開始終了の対応が取れてないときに起こります。

ちゃんと見てないけど、この辺が怪しく思える。

activate|deactivate|rehash|shell)

ソースを部分的にコメントアウトしたり分割したりしてbashに食わせてやれば、問題がどこにあるか特定しやすいでしょう。

投稿2020/03/22 20:30

KojiDoi

総合スコア13669

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問