I have windows, using Cygwin, trying to set JAVA_HOME
permanently through my .bashrc
file.
.bashrc:
export PATH="$JAVA_HOME/bin:$PATH"
export JAVA_HOME=$JAVA_HOME:"/cygdrive/c/Program Files (x86)/Java/jdk1.7.0_05"
.bash_profile:
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
running cygwin:
-bash: $'\377\376if': command not found
-bash: $'then\r': command not found
: No such file or directorysu//.bashrc
-bash: /cygdrive/c/Users/jhsu//.bash_profile: line 3: syntax error near unexpected token `fi'
-bash: /cygdrive/c/Users/jhsu//.bash_profile: line 3: `fi'
I am not sure if I took the commands from a tutorial that was meant for another system or if I am missing a step. Or whitespace is causing my commands not to run properly.
I've looked at multiple similar questions but I haven't found one where the question has my error exactly.
My home path:
$ echo $HOME
/cygdrive/c/Users/jhsu
$ echo ~
/cygdrive/c/Users/jhsu/
So I believe the files should be placed in the correct spot.
You can also add the option
-o igncr
to the bash call, e.g.In EditPlus you do this from the
Document → File Format (CR/LF) → Change File Format...
menu and then choose theUnix / Mac OS X
radio button.If you have the vim package installed on your Cygwin install, you can use vim to fix this without find & replace. Start vim as follows:
vim filename.sh
(often it is aliased to vi also). Then, type:set fileformat=unix
, then:wq
(write & quit) to save your changes. (The:
puts you in vim's edit mode.)I recommend this over dos2unix since vim is probably more commonly installed.
However, it is probably a best practice to set your text editor to save files that you plan to use in a Unix/Linux environment to have a Unix text format. The answers given above for Notepad++ are a good example.
Additional note: If you are unsure what type a file is (DOS or Unix), you may use the
file filename.sh
. This can especially help in debugging more obscure issues (such as encoding issues when importing SQL dumps that come from Windows).For other options on how to modify text file formatting, see this IU knowledge base article
More background information on Bash scripts and line endings is found on this StackOverflow question.
When all else fails in Cygwin...
Try running the
dos2unix
command on the file in question.It might help when you see error messages like this:
-bash: '\r': command not found
Windows style newline characters can cause issues in Cygwin.
The
dos2unix
command modifies newline characters so they are Unix / Cygwin compatible.CAUTION: the dos2unix command modifies files in place, so take precaution if necessary.
If you need to keep the original file, you should back it up first.
Note for Mac users: The
dos2unix
command does not exist on Mac OS X.Check out this answer for a variety of solutions using different tools.
There is also a
unix2dos
command that does the reverse:It modifies Unix newline characters so they're compatible with Windows tools.
If you open a file with Notepad and all the lines run together, try
unix2dos filename
.SUBLIME TEXT
With sublime you just go to
Then save the file. Will fix this issue.
Easy as that!
Issue maybe occured because of the file/script created/downloaded from a windows machine. Please try converting into linux file format.
or