Variable concatenation has strange result in shell script
shell, unix
Solution
To long to put as a comment...
$ ./var.sh
/sbclocal/apps/blablabla
/sbclocal/apps/blablabla
/sbclocal/apps/blablabla/jar
/sbclocal/apps/blablabla/jar
/sbclocal/apps/blablabla/jar
/sbclocal/apps/blablabla/jar
As I said, your scrip works perfectly for me. Somethings to check:
First, change the shebang to `#!/bin/sh -x` to enable debugging and look at the output.
Secondly, run `file var.sh` to check the line endings. Expected result should be:
$ file var.sh
var.sh: POSIX shell script text executable
Convert to unix-format using `dos2unix` or `fromdos`.
Problem
I am writing (my first) shell script, and, for flexibility would like to use variables. Here is a part of script I wrote following different examples searched: ``` #!/bin/sh # jar_path="/sbclocal/apps/blablabla" echo $jar_path # <- OK echo ${jar_path} # <- OK echo $jar_path/jar # <- /jarlocal/apps/blablabla echo "$jar_path/jar" # <- /jarlocal/apps/blablabla echo ${jar_path}/jar # <- /jarlocal/apps/blablabla echo "${jar_path}/jar" # <- /jarlocal/apps/blablabla ``` In the last line, I expect to get "/sbclocal/apps/blablabla/jar", but what I get is "/jarlocal/apps/blablabla"! So instead of concatenation, starting of the variable string is replaced with the constant part, which I expect in the end! There is also more complex concatenation inside of the jar parameter, which gets broken in a way I can't figure out for sure, but I suppose the issue is the same. What is wrong here please? UPD: Edited to show different approaches I tried, all having the same result. UPD: I have also tried with 2 variables, strange thing is that the first one is not shown, like it's empty, when I write something like ``` echo $var1$var2 echo ${var1}${var2} echo ${var1}+${var2} ``` This is crazy, I think I will give up and use old plain copy-paste, as this will be much quicker.