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

find "${HOME}/docs/"

You want the full path in quotes so that paths with spaces are handled properly. Brackets are good practice when concatenating strings.

  • source
  • hideshow 6 child 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
  • [–] 1 point 3 years ago (1 child)

    This shit fucked me up so much when i was learning linux stuff. Especially cause a lot of my file paths had spaces. This is the way.

  • source
  • parent
  • hideshow 2 child comments