• deadbeef79000@lemmy.nz
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    4 months ago

    rm -rf ${var}/ is a disaster waiting to happen.

    Always do rm -rf "${var:?}/" so that the script aborts if the variable is empty. Or better yet rm -rf "./${var:?}/".

    Edited to add quotes. Always quote a path: it might have spaces in it, without quotes that will become multiple paths! Which would also have avoided the particular bug in question.

    • Samueru@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      4 months ago

      In this case the issue was that a change between kde5 and kde6 let to the variable being defined as somepath / (notice the space).

    • mumblerfish@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      4 months ago

      Is there not also a way to disallow empty variables in the script, I think it is set -u? Then you don’t have to keep thinking “should I add a :? here because if empty it may lead to disaster” all the time. Might be even safer.