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.
The . bashrc file is a script file that's executed when a user logs in. The file itself contains a series of configurations for the terminal session. This includes setting up or enabling: coloring, completion, shell history, command aliases, and more. It is a hidden file and simple ls command won't show the file.
R comes with Rscript , a command line tool that can run R scripts or R commands directly from the bash shell. The most compact way to run it is with the -e option containing directly the R expression to evaluate. For example the following command will output 10 random numbers: Rscript -e 'res=runif(10);cat(res,"\n")'
The \r issue suggests you have edited the script file on a Windows machine. Windows uses \r\n as the line terminator while Linux (and most other operating systems) use \n alone. When you edit a file in Windows, Windows will add \r to the end of the lines and that will break your scripts.
steeldriver is correct that the problem is that you have files with Windows line endings and bash cannot run them. $'[&r&]' is a representation of the carriage return character (CR) that is part of traditional DOS and Windows line endings (CR LF), but which is absent in traditional Unix-style line endings (LF).
Bash behaves differently depending on if it believes that it is a login shell, i.e. the first shell run when you log onto a system. It only reads .bash_profile if it is a login shell. If you put the PATH -changing code into .bashrc instead, it will be run for all interactive bash shells, not just login shells.
-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.
It only reads .bash_profile if it is a login shell. If you put the PATH -changing code into .bashrc instead, it will be run for all interactive bash shells, not just login shells. Show activity on this post. If using the Gnome environment in Scientific Linux 6 (or presumably RHEL 6), start a terminal.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With