简体   繁体   English

Mac终端错误-bash:找不到命令-El Capitan 10.11.13

[英]Mac terminal error -bash: command not found - El Capitan 10.11.13

I'm getting an error message when I first open my Mac terminal - 第一次打开Mac终端时出现错误消息-

-bash: Applications: command not found

Oddly (or maybe not so oddly), when I open another tab, I sometimes get a different error - 奇怪的是(或者可能不是很奇怪),当我打开另一个标签时,有时会出现其他错误-

-bash: README.md: command not found

or 要么

-bash: [: missing `]'

I just noticed that this morning... there are two things that I did last night that I feel may have led to this, but I'm not sure if I am correct, nor do I know how to appropriately fix this issue. 我只是注意到今天早上...昨晚我做了两件事,我认为可能导致了这一点,但是我不确定我是否正确,也不知道如何适当地解决此问题。 My OS is El Capitan 10.11.13. 我的操作系统是El Capitan 10.11.13。

First off, last night, I used Homebrew to install PostGIS 2.2 - my Postgres version is 9.5.1. 首先,昨晚,我使用Homebrew安装了PostGIS 2.2-我的Postgres版本是9.5.1。

Second, I made a Github pull request for one of my projects (I'm not sure how a pull request could upset my bash profile, but Github's standard readme format is README.md, so I thought I'd better mention this here). 其次,我为我的一个项目发出了一个Github请求请求(我不确定请求请求会如何破坏我的bash配置文件,但是Github的标准自述文件格式是README.md,所以我想在这里最好提一下) 。

My bash profile seems clean to me - 我的bash个人资料对我来说似乎很干净-

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function
export PATH=${PATH}:/usr/local/mysql/bin
*    #EDITED TO INCLUDE THIS ASTERISK, WHICH I NEGLECTED BEFORE

Can anyone shed some light on what happened and how I can go about fixing this? 任何人都可以阐明发生的事情以及如何解决该问题吗? I'm fairly new to using the terminal, so I'm not quite sure how to interpret this. 我对使用终端还很陌生,所以我不太确定如何解释它。

How to troubleshoot Bash startup problems : 如何解决Bash启动问题

To build on Jonathan Leffler's helpful comment : 乔纳森·莱弗勒(Jonathan Leffler)的有用评论为基础

  • From an existing terminal window, run script log.txt bash -lxv 在现有的终端窗口中,运行script log.txt bash -lxv
    • This will create a new login ( -l ) shell (which is the type of shell Terminal.app on OSX creates by default) and log all its startup activities. 这将创建一个新的登录( -l )外壳程序(这是OSX上默认创建的Terminal.app外壳程序的类型)并记录其所有启动活动。
    • In addition to capturing regular output, 除了捕获常规输出外,
      • -v shows unexpanded source lines as they're being read. -v显示正在读取的未展开的源代码行。
      • -x shows the expanded, individual commands that are executed, prefixed with + . -x显示已执行的, 扩展的单个命令,其前缀为+
  • Execute exit to terminate that shell, which will save everything that was just printed to log.txt . 执行exit终止该外壳程序,该外壳程序会将刚刚打印的所有内容保存到log.txt
  • Study file log.txt to see what's going on. 研究文件log.txt以查看发生了什么。

What turned out to be the OP's problem: 原来是OP的问题:

  • A stray * on a single line in their profile expanded to an alphabetically sorted list of the names of the files and folders in the then-current directory (a process called pathname expansion or globbing). 它们的配置文件中单行上的*符号扩展为按字母顺序排序的当时目录中文件和文件夹名称的列表(此过程称为路径名扩展或遍历)。

    • Not only is a * as its own command (or the start of a command) not useful , it could result in unwanted execution of a command (see below). *不仅因为*本身的命令(或命令的开始)没有 ,还会导致不必要的命令执行 (请参阅下文)。
  • Bash then tried to execute the result of this expansion as a command to execute , with the 1st word (whitespace-separated token) interpreted as the command name . 然后Bash尝试将扩展结果作为要执行命令来执行 ,将第一个单词(用空格分隔的标记)解释为命令

    • This failed, because that first word happened not be a command name. 失败了,因为第一个单词不是命令名称。
    • However, if the first word happened to be a valid command name such as file , that command would execute . 但是,如果第一个单词碰巧是有效的命令名称(例如file ,则该命令将执行
      (Unless the current dir. happens to be in the $PATH , it doesn't matter whether the first matching filename is an executable file or not - all that matters is whether the name matches an existing command name). (除非当前目录恰好位于$PATH ,第一个匹配的文件名是否是可执行文件都没有关系-重要的是名称是否与现有命令名匹配)。
  • On startup, the user's home dir. 在启动时,用户的主目录。 was the working dir.; 是工作目录。 by contrast, opening another tab later uses the then-current working dir., whatever it happens to be. 相比之下,稍后打开另一个选项卡将使用当时当前的工作目录。

    • This explains the differing symptoms, as globbing in different directories will typically result in different name lists, the respective first word of which Bash will try to execute. 这解释了不同的症状,因为在不同目录中进行遍历通常会导致不同的名称列表,Bash将尝试执行其相应的第一个单词。

Thanks to everyone's help here, I was able to resolve this issue. 感谢这里所有人的帮助,我得以解决此问题。 When I posted my question, I left a tiny but important detail out of my bash profile - a lone asterisk on the last line. 当我发布问题时,我在bash个人资料中留下了一个微小但重要的细节-最后一行上有一个单独的星号。

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function

export PATH=${PATH}:/usr/local/mysql/bin  #ADDS MYSQL TO PATH EVERY TIME TERMINAL OPENS
*

I didn't even notice this thing before, let alone understand that it was doing anything. 我什至没有注意到这件事,更不用说了解它在做什么。 I commented it out and now everything runs perfectly. 我将其注释掉,现在一切运行正常。 I'm not sure if this asterisk is a standard part of the bash profile or not, but if it has been there all along, it didn't cause me any trouble until this morning, after I had installed PostGIS and made a Github pull request. 我不确定这个星号是否是bash配置文件的标准部分,但是如果一直存在,直到今天早上,在安装PostGIS并进行Github拉动之后,它才不会给我造成任何麻烦请求。 I'm not sure why those actions would have triggered this problem, but I'm trying to be as descriptive as possible in case anyone else runs into this. 我不确定为什么这些动作会触发此问题,但是我想尽可能地描述一下,以防其他任何人遇到这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM