sun*_*ppy 36 macos bash terminal export
每次打开终端我都会收到以下错误:
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
这是我的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"
Mat*_*Mat 92
=当你这样做时,你不能在标志周围放置空格:
export foo=bar
删除你拥有的空间,你应该很高兴去.
如果输入:
export foo = bar
shell会解释,由于出口三个名字的请求:foo,=和bar.=不是有效的变量名,因此命令失败.变量名称,等号和它的值不能用空格分隔,以便将它们作为同时分配和导出进行处理.
Kee*_*asa 12
我遇到了同样的错误,并进行了一些研究,结果发现该错误可能有不同的情况。让我分享我的发现。
=场景一:等号旁边不能有空格
$ 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
场景 2:对象赋值除了引号之外不应该有空格
$ 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
场景 3:列表值分配不应在值之间有空格
$ export TEMP_ENV=[1,2 ,3 ]
-bash: export: `,3': not a valid identifier
-bash: export: `]': not a valid identifier
我分享这些是因为我被困了几个小时试图找出解决方法。希望它能帮助有需要的人。
我在变量名称中使用破折号“-”而不是下划线“_”。
# fails 
$ export MY-NAME="abc"
# success
$ export MY_NAME="abc"
| 归档时间: | 
 | 
| 查看次数: | 72409 次 | 
| 最近记录: |