• SpaceNoodle@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    1 year ago

    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.

    • Synthead@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      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?

      • RazorsLedge@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        edit-2
        1 year ago
        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

  • DoomBot5@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    First one has the pitfall of a space at the end of the variable still causing it to fail.

    • LemoineFairclough@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 month ago

      I don’t think this is correct. Consider what you see from using sh -c -- 'var="a " && printf "%s\n" "${var}"-z'

      If "${var}"-z resulted in two arguments instead of one, I’d see “a” and “-z” on different lines, but I see them on the same line, which means they are treated as a single argument.

  • Matriks404@lemmy.world
    link
    fedilink
    arrow-up
    0
    arrow-down
    1
    ·
    1 year ago

    Bash has the worst syntax rules I have seen, and the fact that you can do both of these doesn’t help.

    I am probably going to switch to fish for any scripting, Python would probably be better, but it seems to be much more complicated and I am too lazy to learn it.