1

Please help me understand and possibly explain this. Suppose I have 2 env variables:

$REL --> foo
$MEL --> bar

Now if I echo $REL$MEL it works.

If I echo test$REL, it works.(testfoo)

But why Linux is not able to identify the variable when used like this: $RELtest?

I understand this looks like the stupidest question but is there a way to tell the system to look for the matching part of the string in env variables already set and replace that part?

I also understand that when doing test$REL, it is $ that works as an identifier. If this is not possible then how to explain the limitation? Any usage example in docs where this is shown prohibited will help me a lot.

Andreas Fester
  • 36,091
  • 7
  • 95
  • 123
ABX
  • 113
  • 1
  • 4
  • 12
  • You need braces to indicate which parts of the text are the variable name whenit's not all of them. `echo "${REL}test"` – tripleee Oct 05 '15 at 06:40

1 Answers1

3

With $RELtest, the shell interprets it as the value of the variable RELtest - it is not able to figure out that you meant REL followed by a literal test since there is no delimiter. You need to be more explicit - use {} to quote the variable:

$ echo ${REL}test
footest

See also When do we need curly braces in variables using Bash?

Community
  • 1
  • 1
Andreas Fester
  • 36,091
  • 7
  • 95
  • 123