Helping Hands Helping Hands - 4 months ago 5
Linux Question

Getting issue with .bash_profile in linux

I am trying set class path but getting error.

File Code :

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

export JAVA_HOME=/usr/java/jdk1.8.0_91/bin


PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH


It print BLANK when I echo Java classpath.

When I access server via putty , Getting error :

-bash: $'\r': command not found
-bash: /home/test/.bash_profile: line 16: syntax error: unexpected end of file

Answer

The syntax error may related to the CRLF and CR problem, you may resolve this by edit the file in linux side or using a rich editor such as notepad++ which you can save using Linux newline, refer to this post

Beside, you may want to write those scripts in .bashrc

The bash man page on my linux box says:

FILES
   /bin/bash
          The bash executable
   /etc/profile
          The systemwide initialization file, executed for login shells
   ~/.bash_profile
          The personal initialization file, executed for login shells
   ~/.bashrc
          The individual per-interactive-shell startup file
   ~/.bash_logout
          The individual login shell cleanup file, executed when  a  login
          shell exits
   ~/.inputrc
          Individual readline initialization file
   /etc/inputrc
          System readline initialization file

according to this post, the terminal.app on OS X is an exception.

Mac OS X — an exception
An exception to the terminal window guidelines is Mac OS X’s 
Terminal.app, which runs a login shell by default for each new
terminal window, calling .bash_profile instead of .bashrc. Other 
tGUI terminal emulators may do the same, but most tend not to.