I am unable to explain the below behavior. Any ideas ?    Welcome to Ubuntu 12.04.5 LTS (GNU/Linux 3.13.0-32-generic x86_64)     * Documentation:  https://help.ubuntu.com/    New release '14.04.2 LTS' available.    Run 'do-release-upgrade' to upgrade to it.    Last login: Wed Oct 21 22:43:19 2015 from 10.0.2.2    vagrant@master:~$ echo $0    -bash    vagrant@master:~$ export A=/hello    vagrant@master:~$ echo $A    /hello    vagrant@master:~$ echo $A/bin    /hello/bin    vagrant@master:~$ echo $A/bin/asd    /hello/bin/asd    vagrant@master:~$ export A=/hello-2.6.1    vagrant@master:~$ echo $A    /hello-2.6.1    vagrant@master:~$ echo $A/bin    /hello-2.6.1/bin    vagrant@master:~$ echo $A/bin/asd    /hello-2.6.1/bin/asd    vagrant@master:~$ echo $HADOOP_HOME    /opt/hadoop-2.6.1    vagrant@master:~$ echo $HADOOP_HOME/bin    /bin/hadoop-2.6.1    vagrant@master:~$ echo $HADOOP_HOME/bin1234    /bin1234oop-2.6.1    vagrant@master:~$ uname -a    Linux master 3.13.0-32-generic #57~precise1-Ubuntu SMP Tue Jul 15 03:51:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux    vagrant@master:~$ export A=/opt/hadoop-2.6.1    vagrant@master:~$ echo $A/bin    /opt/hadoop-2.6.1/bin    vagrant@master:~$ echo $A/bin/asd    /opt/hadoop-2.6.1/bin/asd    vagrant@master:~$ echo $A    /opt/hadoop-2.6.1    vagrant@master:~$
Why is my shell variable concatenation not working on ubuntu bash?
shell
It looks like your HADOOP_HOME variable has been defined to a valuethat ends with a carriage return, i.e.,/ o p t / h a d o o p - 2 . 6 . 1 carriage returnso when you doecho $HADOOP_HOME/binyou're getting the output/ o p t / h a d o o p - 2 . 6 . 1 carriage return/ b i nonly all on one line, so the /bin overwrites the /opt on the screenand it looks like/bin/hadoop-2.6.1You can check this by doingA=/opt/hadoop-2.6.1echo $A | od -cbecho $HADOOP_HOME | od -cbTry to find where HADOOP_HOME is being defined.It may be one of your . files;e.g., .profile, .bashrc, or .bash_profile in your home directory,or a similarly named file in /etc.If you use vi, it should show a ^M at the end of the string;that represents carriage return. Delete the ^M.