bash “导出:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29065798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:32:30  来源:igfitidea点击:

“export: command not found

macosbashpath

提问by Tim Reznich

When I open terminal on my mac it shows

当我在 Mac 上打开终端时,它显示

Last login: Sun Mar 15 22:12:02 on ttys000
-bash: “export: command not found
-bash: “export: command not found
-bash: “export: command not found
-bash: “export: command not found

(My echo $PATH)

(我的回声 $PATH)

MacBook-Air-Tim:~ timreznik$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/timreznik/bin:/usr/local/bin
MacBook-Air-Tim:~ timreznik$ 

I have already tried to edit my .bash_profile to

我已经尝试将我的 .bash_profile 编辑为

# general path munging
PATH=${PATH}:~/bin
PATH=${PATH}:/usr/local/bin

but it still keep showing me “export: command not found when I launch terminal...

但它仍然不断向我显示“导出:启动终端时找不到命令......

P.S. all commands seems to work but my inner perfectionist is screaming!

PS 所有命令似乎都有效,但我内心的完美主义者在尖叫!

回答by John1024

First, exportis a shell builtin:

首先,export是一个内置的shell:

$ type export
export is a shell builtin

This means that PATHis irrelevant.

这意味着PATH无关紧要。

Second, the error message makes clear that the script is attempting to run the command “export. There is no such command:

其次,错误消息清楚地表明脚本正在尝试运行命令“export。没有这样的命令:

$ “export
bash: $'204export': command not found

The solution is to remove the spurious character from before the string export.

解决方案是从 string 之前删除虚假字符export

This misspelled command is in one of the shell's initialization files. These would include: ~/.bashrc, /etc/bash.bashrc, ~/.bash_profile, ~/.bash_login, ~/.profile, and any files they include.

这个拼写错误的命令位于 shell 的一个初始化文件中。这将包括:~/.bashrc/etc/bash.bashrc~/.bash_profile~/.bash_login~/.profile,和任何文件,他们包括。

Alternatively, the following commands will tell you which files and which lines in those files have the misspelled exportcommand:

或者,以下命令将告诉您哪些文件以及这些文件中的哪些行具有拼写错误的export命令:

PS4='+ $BASH_SOURCE:$LINENO:' BASH_XTRACEFD=7 bash -xlic ""  7>trace.out
grep '“export' trace.out

For details on how the above works, see this post.

有关上述工作原理的详细信息,请参阅此帖子

回答by zbstof

I had a similar problem, the culprit was non-breaking spacebetween exportand the name of the variable. To resolve the issue, just replace it with a regular space character.

我有一个类似的问题,罪魁祸首是变量名 和之间的不间断空格export。要解决此问题,只需将其替换为常规空格字符即可。

Details: I had the following in .bash_profile:

详细信息:我有以下内容.bash_profile

export?a=foo

When I start new terminal, I would get

当我开始新的终端时,我会得到

-bash: export?a=foo: command not found

If we run xxdon the file, however, we can plainly see the problem (dots are non-printable characters:

xxd但是,如果我们在文件上运行,我们可以清楚地看到问题(点是不可打印的字符:

$ cat .bash_profile | head -n1 | xxd
00000000: 6578 706f 7274 c2a0 613d 666f 6f       export..a=foo

Byte sequence c2a0stands for non-breaking space

字节序列c2a0代表不间断空间