this post was submitted on 13 Nov 2025
17 points (94.7% liked)

Linux

10125 readers
1592 users here now

A community for everything relating to the GNU/Linux operating system (except the memes!)

Also, check out:

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 2 years ago
MODERATORS
 

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

you are viewing a single comment's thread
view the rest of the comments
[–] IanTwenty@piefed.social 18 points 2 days ago* (last edited 2 days ago) (3 children)

$() for me, to quote from

https://www.shellcheck.net/wiki/SC2006

Backtick command substitution `...` is legacy syntax with several issues.

  1. It has a series of undefined behaviors related to quoting in POSIX.
  2. It imposes a custom escaping mode with surprising results.
  3. It's exceptionally hard to nest.

$(...) command substitution has none of these problems, and is therefore strongly encouraged.

[–] confusedpuppy@lemmy.dbzer0.com 4 points 2 days ago (2 children)

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 5 points 2 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.

load more comments (1 replies)
load more comments (1 replies)