0

Execute the following command in bash shell:

export sz1='"authorities" : ["uaa.resource"]'

Now, try echo $sz1

I expect to see the following output:

"authorities" : ["uaa.resource"]

But instead I get this:

"authorities" : c

The interesting thing is that I have dozens of servers where I can execute this type of variable assignment and it works except on this server. This server has exactly the same OS version, profile, bash version etc. What could be the reason for this behavior?

Barmar
  • 741,623
  • 53
  • 500
  • 612
madmax
  • 76
  • 4
  • Hint: that one computer has a file named "c" in the current working directory where you run this. This looks like a duplicate of ["I just assigned a variable, but echo $variable shows something else"](https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else). – Gordon Davisson Jul 22 '20 at 16:27
  • Thanks a lot Barmar. Yes, this solves the issue. – madmax Jul 23 '20 at 20:35

1 Answers1

0

Always quote your variables. Use

echo "$sz1"

When you don't quote the variable, word splitting and wildcard expansion is done on the variable expansion. On ["uaa.resource"] is a wildcard that will match any of the following filenames:

"
u
a
.
r
e
s
o
u
c

On that one machine you have a file named c, so the wildcard matches and gets replaced with that filename.

Barmar
  • 741,623
  • 53
  • 500
  • 612