10

In Pycharm when we use variable e.g. $privateKey, we get the warning Simple variable usage as below snapshot and recommend us to turn to the syntax ${privateKey}

My question is why we get such warning? What is the risk to use simple variable like that?

enter image description here

When clicking more

enter image description here

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
  • It is perfectly valid and not-problematic in your use case, what does clicking the `more` link show? – heemayl Nov 14 '16 at 04:39
  • It shows ${X} syntax as my added 2nd snapshot @heemayl – Nam G VU Nov 14 '16 at 05:29
  • 1
    Sorry but I still don't see the reason to have a warning like this. If we know what we are doing, we can perfectly use `$privateKey` for a bash variable... – Jean Paul Sep 25 '18 at 13:49

1 Answers1

9

Thanks to @Whymarrh. One answer is as below.

since "$foobar" would instead expand foobar

My answer is to separate/distinguish $myVar and notInVar in string "$myVarnotInVar"

In other words

myVar=122

echo "$myVarnotInVar" # will print empty string "" since undefined variable $myVarnotInVar

echo "${myVar}notInVar" # will print 122notInVar
Nam G VU
  • 33,193
  • 69
  • 233
  • 372