-bash: export: `=': 不是一个有效的标识符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18042369/
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
-bash: export: `=': not a valid identifier
提问by sunkehappy
Every time I open my terminal I get the error below:
每次打开终端时,都会出现以下错误:
Last login: Sun Aug 4 17:23:05 on ttys000
-bash: export: `=': not a valid identifier
-bash: export: `/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin': not a valid identifier
-bash: export: `=': not a valid identifier
-bash: export: `/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin': not a valid identifier
And here is my export
output:
这是我的export
输出:
Calvin:~ sunkehappy$ export
declare -x Apple_PubSub_Socket_Render="/tmp/launch-4lEZNa/Render"
declare -x Apple_Ubiquity_Message="/tmp/launch-ukGAv5/Apple_Ubiquity_Message"
declare -x COMMAND_MODE="unix2003"
declare -x HOME="/Users/sunkehappy"
declare -x LANG="zh_CN.UTF-8"
declare -x LOGNAME="sunkehappy"
declare -x OLDPWD
declare -x PATH="/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
declare -x PWD="/Users/sunkehappy"
declare -x SECURITYSESSIONID="186a4"
declare -x SHELL="/bin/bash"
declare -x SHLVL="1"
declare -x SSH_AUTH_SOCK="/tmp/launch-YAEryC/Listeners"
declare -x TERM="xterm-256color"
declare -x TERM_PROGRAM="Apple_Terminal"
declare -x TERM_PROGRAM_VERSION="309"
declare -x TERM_SESSION_ID="B134A404-D87F-4BB9-8A08-55F8CE923339"
declare -x TMPDIR="/var/folders/kt/pfw99tps22gg2019vz8k1zcm0000gn/T/"
declare -x USER="sunkehappy"
declare -x __CF_USER_TEXT_ENCODING="0x1F5:25:52"
回答by Mat
You cannot put spaces around the =
sign when you do:
=
当您执行以下操作时,您不能在标志周围放置空格:
export foo=bar
Remove the spaces you have and you should be good to go.
删除您拥有的空间,您应该很高兴。
If you type:
如果您键入:
export foo = bar
the shell will interpret that as a request to export three names: foo
, =
and bar
. =
isn't a valid variable name, so the command fails. The variable name, equals sign and it's value must not be separated by spaces for them to be processed as a simultaneous assignment and export.
shell 会将其解释为导出三个名称的请求:foo
,=
和bar
. =
不是有效的变量名,因此命令失败。变量名、等号和它的值不能用空格分隔,以便它们作为同时赋值和导出处理。
回答by tk 421
I had the same problem and figured it out from your comments, but thought I would add the reason I caused the error to occur (for other beginners).
我遇到了同样的问题并从您的评论中弄清楚了,但我想我会添加导致错误发生的原因(对于其他初学者)。
I had opened and edited .bash_profile using the open command in Terminal, which opened it in Text Editor. I typed in an addition to .bash_profile and it used improper quote characters. I opened .bash_profile in Atom and fixed up the error. I also associated the file with Atom for future editing.
我在终端中使用 open 命令打开并编辑了 .bash_profile,在文本编辑器中打开它。我在 .bash_profile 中输入了一个补充,它使用了不正确的引号字符。我在 Atom 中打开了 .bash_profile 并修复了错误。我还将该文件与 Atom 相关联以供将来编辑。
回答by Dorcioman
Try to surround the path with quotes, and remove the spaces
尝试用引号将路径括起来,并删除空格
export PYTHONPATH="/home/user/my_project":$PYTHONPATH
And don't forget to preserve previous content suffixing by :$PYTHONPATH(which is the value of the variable)
并且不要忘记通过:$PYTHONPATH保留以前的内容后缀(这是变量的值)
Execute the following command to check everything is configured correctly:
执行以下命令以检查一切配置是否正确:
echo $PYTHONPATH
回答by Keet Sugathadasa
I faced the same error and did some research to only see that there could be different scenarios to this error. Let me share my findings.
我遇到了同样的错误,并做了一些研究,只看到这个错误可能有不同的情况。让我分享我的发现。
Scenario 1: There cannot be spaces beside the =
(equals) sign
场景一:(=
等号)旁边不能有空格
$ export TEMP_ENV = example-value
-bash: export: `=': not a valid identifier
// this is the answer to the question
$ export TEMP_ENV =example-value
-bash: export: `=example-value': not a valid identifier
$ export TEMP_ENV= example-value
-bash: export: `example-value': not a valid identifier
Scenario 2: Object value assignment should not have spaces besides quotes
场景二:对象赋值时不应该有引号之外的空格
$ export TEMP_ENV={ "key" : "json example" }
-bash: export: `:': not a valid identifier
-bash: export: `json example': not a valid identifier
-bash: export: `}': not a valid identifier
Scenario 3: List value assignment should not have spaces between values
场景 3:列表值赋值不应在值之间有空格
$ export TEMP_ENV=[1,2 ,3 ]
-bash: export: `,3': not a valid identifier
-bash: export: `]': not a valid identifier
I'm sharing these, because I was stuck for a couple of hours trying to figure out a workaround. Hopefully, it will help someone in need.
我正在分享这些,因为我被困了几个小时试图找出解决方法。希望它能帮助有需要的人。