简体   繁体   中英

Why am I getting a syntax near unexpected token newline error?

I am trying to create a .bashrc file with the android dev kit in Ubuntu. Only problem is, when i edit/ add to the bashrc file, I get a "syntax error near unexpected token newline". I posted the code where the error is, specifially between android SDK home token and android NDK token. Thanks for the help

 #Android SDK Home
  export ANDROID_SDK=</Documents/adt-bundle-linux-x86_64-20140702>
 #ANDROID NDK Home
 export NDK=~/android-ndk-r10b
 export PATH=$PATH: $ANDROID_SDK/tools:$ANDROID_SDK/platform-tools

I guess that you have read something like this in a guide somewhere:

Add the following lines to your .bashrc file:

 export ANDROID_SDK=<path/to/your/SDK> # etc. 

The < > are meant as placeholders, ie <replace this bit> . You don't need to put the path inside them, in fact you should remove them, as they are invalid syntax (which is causing the error you mention). Also, you should remove the space between $PATH: $ANDROID_SDK later on:

#Android SDK Home
export ANDROID_SDK="/Documents/adt-bundle-linux-x86_64-20140702"
#ANDROID NDK Home
export NDK="$HOME/android-ndk-r10b"
export PATH="$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools"

To be more specific, the error was caused by the > at the end of the export line, as this means "redirect the output of the command to the following file descriptor". Bash is then expecting the name of a file descriptor but all it found was a newline. The < at the beginning is also problematic, as it means "redirect the contents of this file descriptor to the command", which won't do anything useful in your case. See this wiki page for more details.

By the way, there's no harm in using double quotes, in fact, they're encouraged. Using them means that word splitting will not occur in case the name of a directory contains a space. I've added some around your assignments and changed ~ to $HOME , so that it will still do what you want (the ~ will be interpreted literally within double quotes, whereas $HOME will expand to the path of your home directory).

尖括号不适用于这种方式。

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