简体   繁体   中英

-bash: export: not a valid identifier

I'm incredibly new to mobile application development and opted for the HTML/CSS/JavaScript approach via Cordova. I'm encountering this error when trying to amend my PATH and ANDROID_HOME in my .bash_profile and exporting either $PATH or $HOME:

-bash: export: `/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Development/android-sdk-macosx/tools:/Development/android-sdk-macosx/platform-tools': not a valid identifier

I can see a space at the start of the path there but I've checked the .bash_profile and there is no space to be removed? After reading around I thought I'd check the .bashrc to see if a space is being thrown in from somewhere else, but apparently:

.bashrc does not exist

Thanks for taking the time to read this and I appreciate any help given!

The text not a valid identifier is complaining about an identifier that's set to that given value. That's often caused by improper use of $ on the left side of an assignment, something like:

export $PATH=something

It should instead be:

export PATH=something

If that's not the case, check for spaces on either side of the = . Having those, most likely after the = can also cause this issue you're seeing.

When appending to the path, the syntax looks like:

PATH=$PATH:/path/to/something

or:

export ANDROID_HOME=/path/to/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

If you're really interested in seeing why the export is failing, a trick I often use is to change:

export xyzzy=$plugh/folder

into something that echos it first:

echo "[export xyzzy=$plugh/folder]"
export xyzzy=$plugh/folder

That way, I can see exactly how the command will be interpreted after substitutions have taken place. The other possibility there is to add set -x and set +x around the export line since that will cause the bash shell to echo the statement before executing it.

Sometimes I'll just put set -x near the top of the script so that all commands are echoed before execution but that requires a bit of searching to narrow down the issue.

I solved this issue using comments from Jesper in this post. I edited my .bash_profile to reflect the following:

export ANDROID_HOME=/Users/Appa/Development/android-sdk-macosx export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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