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.
I prefer this as well, but just adding that Fish also supports $() for those that don't know.
I keep hearing people that haven't used modern versions of Fish say that it's somewhat different from Bash and strays from POSIX compatibility quite a bit. While the latter is true, Fish has added many bash-isms over the years, so most scripting idioms you're familiar with will work there too.
By some sheer coincidence, I searched this topic today. I’ve been a consistent user of the parenthesis expansion, but never thought of why I preferred one or the other.
I suppose the primary advantage is that $() will expand in a consistent way. You can even nest quotes and more expansions in one, while you’d struggle the same with backtick notation.
$() for me, to quote from
https://www.shellcheck.net/wiki/SC2006
Shellcheckis 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.
Shellcheck has helped me learn a lot about scripting and I strongly recommend using it too.
That's good. There are also editors that can run it for you and highlight the issues whilst you type, neovim being one.
Why wrap it in a function at all? Why not just put the if at the top of the file?
never backquotes, it's unintuitive
$()
Backticks are pretty old syntax.
Deprecated btw.
I'm using fish, so it's ().
I prefer this as well, but just adding that Fish also supports
$()for those that don't know.I keep hearing people that haven't used modern versions of Fish say that it's somewhat different from Bash and strays from POSIX compatibility quite a bit. While the latter is true, Fish has added many bash-isms over the years, so most scripting idioms you're familiar with will work there too.
By some sheer coincidence, I searched this topic today. I’ve been a consistent user of the parenthesis expansion, but never thought of why I preferred one or the other.
I suppose the primary advantage is that $() will expand in a consistent way. You can even nest quotes and more expansions in one, while you’d struggle the same with backtick notation.
So I’ll just keep using parentheses.
@kiri
$()
Better reachable on german keyboard. Also muscle memory … YmmMV. ;-)