Looks like $(…) is better, but I still pretty often see `…` in some articles.

  • confusedpuppy@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    4
    ·
    3 days ago

    Shellcheck is a great tool for scripting.

    When I’m building a new script, I usually add the following function to the script and run the function before anything else. The script will exit immediately if any issues are found so I have a chance to correct things. If no issues are found, the script will simply continue.

    It’s small and simple so it’s easy to remove when I’m done building a script.

    script_check() {
        if ! shellcheck "${0}"; then
            exit 1
        fi
    }
    
    script_check
    

    Shellcheck has helped me learn a lot about scripting and I strongly recommend using it too.

    • IanTwenty@piefed.social
      link
      fedilink
      English
      arrow-up
      5
      ·
      3 days ago

      That’s good. There are also editors that can run it for you and highlight the issues whilst you type, neovim being one.