you are viewing a single comment's thread
view the rest of the comments
[–] 7 points 3 years ago (2 children)

If the strings don't contain characters that help define a variable, like an underscore, how is it better practice to use curlies? It's it just for consistency? Have you had any style guides or linters critique the use of variables without them?

  • source
  • parent
  • hideshow 4 child comments
  • [–] 24 points 3 years ago* (1 child)
    foo=ding
    foobar=dong
    
    echo \$foobar
    
    

    Brackets make it explicit what you're trying to do. Do you want "dingbar" or do you want "dong"? I forget what the actual behavior is if you don't use brackets here, because I always use brackets for this reason now

  • source
  • parent
  • hideshow 2 child comments
  • [–] 5 points 3 years ago (1 child)

    I believe the actual behavior here would be printing β€œdong” as the shell interpreter is greedy in its evaluation of variables.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 years ago (1 child)

    the actual behavior here is to echo the literal string "$foobar", because the $ sign is escaped. so no variable expansion will take place at all.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 2 years ago (2 children)

    Oh lol. It doesn't show the $ at all on my mobile app till I escaped it

  • source
  • parent
  • hideshow 4 child comments