savannah-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Savannah-cvs] [723] style guide: warn about more cases, be more concise


From: iank
Subject: [Savannah-cvs] [723] style guide: warn about more cases, be more concise
Date: Wed, 13 Dec 2023 19:59:59 -0500 (EST)

Revision: 723
          
http://svn.savannah.gnu.org/viewvc/?view=rev&root=administration&revision=723
Author:   iank
Date:     2023-12-13 19:59:58 -0500 (Wed, 13 Dec 2023)
Log Message:
-----------
style guide: warn about more cases, be more concise

Modified Paths:
--------------
    trunk/sviki/fsf/bash-style-guide.mdwn

Modified: trunk/sviki/fsf/bash-style-guide.mdwn
===================================================================
--- trunk/sviki/fsf/bash-style-guide.mdwn       2023-12-13 23:32:06 UTC (rev 
722)
+++ trunk/sviki/fsf/bash-style-guide.mdwn       2023-12-14 00:59:58 UTC (rev 
723)
@@ -283,15 +283,24 @@
 echo hello "$var"
 ```
 
-Note that `var=` as shown above would be a global variable.  In a
-function body, it is best to declare variables as function-local, as
-noted in the 'Variables:' section. However, don't set the variable like
-`local x=$(cmd)` because that has the same problem. Instead, `local x;
-x=$(cmd)`. Shellcheck notices this as warning SC2155.  If the variable should
-be declared with `local`, `declare`, `readonly`, etc, declare it without
-a value, then set it's value separately (eg: `local var`, or `local tmp`
-in the previous example).
+Same deal for all of these:
 
+```
+for f in $(command-that-could-fail); do true; done
+if [[ $(command-that-could-fail) != x ]]; do true; done
+local var=$(command-that-could-fail)
+declare var=$(command-that-could-fail)
+readonly var=$(command-that-could-fail)
+```
+
+Declare, then assign:
+
+```
+local var
+var=$(command-that-could-fail)
+```
+
+
 ### Arithmetic expressions
 
 If there is a syntax error in a conditional expression `(( expression ))`,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]