> On Apr 12, 2021, at 10:57 AM, Oğuz <oguzismailuy...@gmail.com> wrote: > 12 Nisan 2021 Pazartesi tarihinde David A. Wheeler via austin-group-l at The > Open Group <austin-group-l@opengroup.org > <mailto:austin-group-l@opengroup.org>> yazdı: > If you want a robust shell script, I recommend that you try out the tool > “shellcheck”. > That checks a shell script against a set of recommended practices (e.g., use > “$variable” not $variable). > > If it makes that suggestion no matter what context `$variable' is used in, I > don't see how it'll help make a shell script "robust”.
It’s very common advice to recommend using double-quotes on variable expansions unless you have a *good* reason to do otherwise in shell scripts, because it prevents word splitting on a variable reference, and in most cases you do NOT want the word splitting. Examples: * For example, the "Advanced Bash-Scripting Guide” says, “When referencing a variable, it is generally advisable to enclose its name in double quotes.” https://tldp.org/LDP/abs/html/quotingvar.html * The “Quotes” page says: "When in doubt, double-quote every expansion in your shell commands.” https://mywiki.wooledge.org/Quotes#I.27m_Too_Lazy_to_Read.2C_Just_Tell_Me_What_to_Do * https://www.tecmint.com/useful-tips-for-writing-bash-scripts-in-linux/ * https://levelup.gitconnected.com/9-tips-for-writing-safer-shell-scripts-b0c185da9bae#729e Yes, there are rare cases where you *do* want word-splitting. In those cases, omit the double-quotes, and shellcheck lets you disable checks in specific uses when you actually *did* want this. Following the rule “always double-quote unless you have special reasons” means that you don’t have to do program-wide analysis to think about word-splitting in most variable references. As a result, it tends to make creating *reliable* scripts easier. --- David A. Wheeler