Laravel 每个项目安装的 Homestead Bash 找不到别名命令

Laravel Homestead Per Project Install Bash Aliases Commands Not Found

我已经为每个项目安装了 Homestead。我已经包含 after.sh (在根目录中)以毫无问题地提供 RethinkDB 等其他包,但是 aliases 文件(也在根目录中)虽然在 VM 中显示为 ~/.bash_aliases 不是 运行 当我输入任何别名时。例如这些别名:

alias artisan='php artisan'
alias autoload='composer dump-autoload'

在命令提示符中为:

artisan migrate:refresh --seed
autoload

抛出这些错误:

Could not open input file: artisan
autoload: command not found

我尝试的任何别名都会出现这种情况。我已经使用 nano 检查过 ~/.bash_aliases(或 /home/vagrant/.bash_aliases)是否存在,它绝对是别名的副本。只有 none 的命令被使用,就好像它不存在一样,或者就好像位于正确位置的文件无法访问一样。

有人知道为什么吗?或者如何解决这个问题?令人惊奇的是,无法使用我通常在本地使用的别名,或者在使用此 VM 时在全局安装 Homestead 时无法使用这些别名。

更新

我注意到,当我通过 SSH 连接到 VM 时,我得到了一个 command not found 错误列表,该列表与我包含的别名数量相等。如果我 运行 source ~/.bash_aliases,则会出现相同的列表。为清楚起见,.bash_aliases 位于映射源文件夹 /home/vagrant/app 旁边的 /home/vagrant 中,从 SSH 连接到 VM 的输出以及相关的别名文件都包含在内:

SSH 进入虚拟机

$ vagrant ssh
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-25-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Mon Feb 15 00:37:39 2016 from 10.0.2.2
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
vagrant@app:~$

别名文件

# Homestead --------------------------------------------------------------------

alias ..="cd .."
alias ...="cd ../.."

alias h='cd ~'
alias c='clear'

alias phpspec='vendor/bin/phpspec'
alias phpunit='vendor/bin/phpunit'

# Laravel ----------------------------------------------------------------------

# Access Artisan when within project folder
alias artisan='php artisan'

# Access Tinker when within project folder
alias tinker="php artisan tinker --env=local"

# Composer --------------------------------------------------------------------

alias autoload='composer dump-autoload'

# App -------------------------------------------------------------------------

alias app="cd app"

After.sh 文件

#!/usr/bin/env bash

#
# Install RethinkDB on Ubuntu
# @see https://www.rethinkdb.com/docs/install/ubuntu/
#

# Add RethinkDB repository and install
source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y rethinkdb

# Setup RethinkDB as a service using default configuration file
#sudo cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf
#sudo vim /etc/rethinkdb/instances.d/instance1.conf
#sudo /etc/init.d/rethinkdb restart

# Setup RethinkDB as a service by copying the custom configuration file
sudo cp /home/vagrant/app/rethinkdb.conf /etc/rethinkdb/instances.d/instance1.conf
sudo /etc/init.d/rethinkdb restart

更新 2

.bash_aliases 的 Nano 输出,它看起来像我的别名文件,但是 alias t运行 之后的输出包含别名的第一个字母。

# Homestead ----------------------------------------------------------------------

alias ..="cd .."
alias ...="cd ../.."

alias h='cd ~'
alias c='clear'

alias phpspec='vendor/bin/phpspec'
alias phpunit='vendor/bin/phpunit'

# Laravel ----------------------------------------------------------------------

# Access Artisan when within project folder
alias artisan='php artisan'

# Access Tinker when within project folder
alias tinker="php artisan tinker --env=local"

# Composer --------------------------------------------------------------------

alias autoload='composer dump-autoload'

在终端中输入 alias 的输出:

vagrant@app:~$ alias
'lias ..='cd ..
'lias ...='cd ../..
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
'lias artisan='php artisan
'lias autoload='composer dump-autoload
'lias c='clear
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
'lias h='cd ~
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
'lias phpspec='vendor/bin/phpspec
'lias phpunit='vendor/bin/phpunit
'lias tinker='php artisan tinker --env=local

最终解决方案

感谢@JoshRumbut 解决了这个问题,请参阅下面的评论。

vagrant@app:~$ tr -d '\r' <~/.bash_aliases >~/tmp
vagrant@app:~$ mv ~/tmp ~/.bash_aliases
vagrant@app:~$ unalias -a
vagrant@app:~$ source .bash_aliases

bash 是否配置为在 .bash_aliases 文件中查找?

如果你 运行 source ~/.bash_aliases 会怎样?那它们有用吗?

编辑:目前的理论是一个奇怪的字符,可能是回车 return (\r) 嵌入在文件的某处,如问题:https://unix.stackexchange.com/questions/35642/why-are-these-aliases-failing