User Tools

Site Tools


bash:shellcheck

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
bash:shellcheck [2016/10/17 14:21] – created peterbash:shellcheck [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Bash - ShellCheck ======+====== BASH - ShellCheck ======
  
 [[https://github.com/koalaman/shellcheck|ShellCheck]] helps to identify a lot of potential issues in your shell scripts.   [[https://github.com/koalaman/shellcheck|ShellCheck]] helps to identify a lot of potential issues in your shell scripts.  
Line 13: Line 13:
 rm -rf "$dir" rm -rf "$dir"
 </code> </code>
 +
 +----
  
 ===== More Bad Code Examples ===== ===== More Bad Code Examples =====
  
-===== Common beginner's mistakes =====+==== Common beginner's mistakes ==== 
 + 
 +ShellCheck recognizes many common beginner's syntax errors.
  
 <code bash> <code bash>
 +var = 42                              # Spaces around = in assignments.
 +$foo=42                               # $ in assignments.
 +for $var in *; do ...                 # $ in for loop variables.
 +var$n="Hello"                         # Wrong indirect assignment.
 +echo ${var$n}                         # Wrong indirect reference.
 +var=(1, 2, 3)                         # Comma separated arrays.
 </code> </code>
  
-===== Shell bad code =====+---- 
 + 
 +==== Style ==== 
 + 
 +ShellCheck can make recommendations to improve style: 
 + 
 +<code bash> 
 +[[ -z $(find /tmp | grep msg) ]]      # Use grep -q instead. 
 +a >> log; b >> log; c >> log;         # Use a redirection block instead. 
 +cat file | grep foo                   # Useless use of cat. 
 +</code> 
 + 
  
 ShellCheck is very easy to install and use. It is built and packaged using Cabal. We can install by apt-get/yum. Or use cabal-install directly like below. ShellCheck is very easy to install and use. It is built and packaged using Cabal. We can install by apt-get/yum. Or use cabal-install directly like below.
Line 53: Line 75:
          
 It is recommended to enforce a daily Shell Code Check! It is recommended to enforce a daily Shell Code Check!
 +
bash/shellcheck.1476714104.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki