Установка ShellCheck в Unix/Linux

Установка ShellCheck в Unix/Linux

ShellCheck — утилита для отладки ваших shell скриптов. Он позволит улучшить ваши написанные bash скрипты.

Установка ShellCheck в Debian/Ubuntu Linux

Выполняем команду:

# apt install shellcheck -y

Очень простая установка.

Установка ShellCheck в CentOS/RHEL/Fedora/Oracle Linux

Для начала, подключаем EPEL репозиторий, описание тут — включить EPEL репозиторий на CentOS

После чего, выполняем:

# yum install ShellCheck -y

PS: При использовании, Fedora — можно использовать:

# dnf install ShellCheck -y

Установка ShellCheck в Arch Linux

Выполняем команду:

# pacman -S shellcheck

Установка ShellCheck в Gentoo Linux

Выполняем команду:

# emerge --ask shellcheck

Установка ShellCheck в OpenSUSE Linux

Выполняем команду:

# zypper in ShellCheck

Установка ShellCheck в macOS Unix

Подключаем HOMEBREW, если нужно помощь, вот запить о том как можно выполнить установку brew — Установка homebrew на Mac OS X

Далее, стоит выполнить:

$ brew install shellcheck

Можно переходить к использовании.

Использование ShellCheck в Unix/Linux

Приведу наглядный пример использования данной утилиты на примере моего написанного скрипта. Для начала, я его возьму из гита:

# cd /usr/local/src && wget raw.githubusercontent.com/SebastianUA/redis/master/flush-cache.sh

И после чего, запускаем тестирование:

# shellcheck flush-cache.sh

Получаем вывод:

In flush-cache.sh line 1:
#!/usr/bin/env bash -x
^-- SC2096: On most OS, shebangs can only specify a single parameter.


In flush-cache.sh line 18:
SETCOLOR_NUMBERS="echo -en \\033[0;34m" #BLUE
^-- SC2034: SETCOLOR_NUMBERS appears unused. Verify it or export it.


In flush-cache.sh line 21:
if [ "`whoami`" = "root" ]; then
      ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 56:
     echo" `whoami 2> /dev/null` doesn't have permissions. Please use ROOT user for it!";
           ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 64:
      echo "**************************************************************" >> $FlushCacheReport
      ^-- SC2129: Consider using { cmd1; cmd2; } >> file instead of individual redirects.


In flush-cache.sh line 65:
      echo "HOSTNAME: `hostname`" >> $FlushCacheReport
                      ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 78:
                  echo "expect has been INSTALLED on this server: `hostname`";
                                                                  ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 82:
                  echo "expect INSTALLED on this server: `hostname`";
                                                         ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 86:
            if [ -z "`rpm -qa | grep mailx`" ]; then
                     ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 89:
                  echo "service of mail has been installed on `hostname`";
                                                              ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 93:
                  echo "mailx INSTALLED on this server: `hostname`";
                                                        ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 102:
                        echo "expect has been INSTALLED on this server: `hostname`";
                                                                        ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 106:
                        echo "expect INSTALLED on this server: `hostname`";
                                                               ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 110:
                  if [ -z "`which mailx`" ]; then
                           ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 113:
                        echo "service of mail has been installed on `hostname`";
                                                                    ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 117:
                        echo "mailx INSTALLED on this server: `hostname`";
                                                              ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 123:
                  echo 'OS=' $OS 'VER=' $VER
                             ^-- SC2086: Double quote to prevent globbing and word splitting.
                                        ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 130:
     if [ $? -eq 0 ]; then
          ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.


In flush-cache.sh line 132:
         echo -n "$(tput hpa $(tput cols))$(tput cub 6)[OK]"
                             ^-- SC2046: Quote this to prevent word splitting.


In flush-cache.sh line 137:
        echo -n "$(tput hpa $(tput cols))$(tput cub 6)[fail]"
                            ^-- SC2046: Quote this to prevent word splitting.


In flush-cache.sh line 144:
    for Roots in `echo $RootF|xargs -I{} -n1 echo {}` ; do
                 ^-- SC2006: Use $(..) instead of legacy `..`.
                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 156:
         for Iconfig in `ls -al /etc/nginx/conf.d/*.conf | grep "^-"| grep -vE "(default|geo|example)"|awk '{print $9}'|xargs -I{} -n1 echo {}` ; do
                        ^-- SC2006: Use $(..) instead of legacy `..`.
                         ^-- SC2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.


In flush-cache.sh line 157:
              RootF=$(cat $Iconfig 2> /dev/null| grep root|cut -d ";" -f1 | awk '{print $2}'|grep -vE "(SCRIPT_FILENAME|fastcgi_param|fastcgi_script_name|log|-f)"|uniq| grep -vE "(blog|wp)")
                          ^-- SC2086: Double quote to prevent globbing and word splitting.
                          ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 158:
              SITE=$(cat $Iconfig 2> /dev/null| grep "server_name"|awk '{print $2}'|cut -d ";" -f1)
                         ^-- SC2086: Double quote to prevent globbing and word splitting.
                         ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 159:
              echo $SITE
                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 165:
           for Iconfig in `ls -alR /etc/httpd/conf.d/*.conf | grep "^-"| grep -vE "(default|geo|example)"|awk '{print $9}'|xargs -I{} -n1 echo {}` ; do
                          ^-- SC2006: Use $(..) instead of legacy `..`.
                           ^-- SC2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.


In flush-cache.sh line 166:
                RootF=$(cat $Iconfig 2> /dev/null| grep DocumentRoot| cut -d '"' -f2|uniq| grep -v "blog")
                            ^-- SC2086: Double quote to prevent globbing and word splitting.
                            ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 167:
                SITE=$(cat $Iconfig 2> /dev/null| grep -E "ServerName"|awk '{print $2}')
                           ^-- SC2086: Double quote to prevent globbing and word splitting.
                           ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 172:
         echo "Please check which web-server installed on `hostname`";
                                                          ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 179:
         for Iconfig in `ls -al /etc/nginx/conf.d/*.conf | grep "^-"| grep -vE "(default|geo|example)"|awk '{print $9}'|xargs -I{} -n1 echo {}` ; do
                        ^-- SC2006: Use $(..) instead of legacy `..`.
                         ^-- SC2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.


In flush-cache.sh line 180:
              RootF=$(cat $Iconfig 2> /dev/null| grep root|cut -d ";" -f1 | awk '{print $2}'|grep -vE "(SCRIPT_FILENAME|fastcgi_param|fastcgi_script_name|log|-f)"|uniq| grep -vE "(blog|wp)")
                          ^-- SC2086: Double quote to prevent globbing and word splitting.
                          ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 181:
              SITE=$(cat $Iconfig 2> /dev/null| grep "server_name"|awk '{print $2}'|cut -d ";" -f1)
                         ^-- SC2086: Double quote to prevent globbing and word splitting.
                         ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 182:
              echo $SITE
                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 189:
           for Iconfig in `ls -alR /etc/apache2/sites-enabled/*.conf| awk '{print $9}'|xargs -I{} -n1 echo {}` ; do
                          ^-- SC2006: Use $(..) instead of legacy `..`.
                           ^-- SC2012: Use find instead of ls to better handle non-alphanumeric filenames.


In flush-cache.sh line 190:
                RootF=$(cat $Iconfig 2> /dev/null| grep DocumentRoot| cut -d '"' -f2|uniq| grep -v "blog")
                            ^-- SC2086: Double quote to prevent globbing and word splitting.
                            ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 191:
                SITE=$(cat $Iconfig 2> /dev/null| grep -E "ServerName"|awk '{print $2}')
                           ^-- SC2086: Double quote to prevent globbing and word splitting.
                           ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 196:
         echo "Please check which web-server2 installed on `hostname`";
                                                           ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 209:
  CacheRedisIP=$(cat `echo $LocalXML` 2> /dev/null| grep Cache_Backend_Redis -A13| grep "<server>"|uniq|cut -d ">" -f2 | cut -d "<" -f1)
                     ^-- SC2046: Quote this to prevent word splitting.
                     ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                     ^-- SC2006: Use $(..) instead of legacy `..`.
                     ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                           ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 211:
             CacheRedisIP=$(cat `echo $LocalXML` 2> /dev/null| grep Cache_Backend_Redis -A13| grep "<server>"| uniq|cut -d "[" -f3| cut -d "]" -f1)
                                ^-- SC2046: Quote this to prevent word splitting.
                                ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                                ^-- SC2006: Use $(..) instead of legacy `..`.
                                ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                      ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 215:
  CacheRedisSock=$(cat `echo $LocalXML` 2> /dev/null| grep Cache_Backend_Redis -A13| grep "<server>"|uniq| cut -d ">" -f2|cut -d "<" -f1| cut -d "." -f2)
                       ^-- SC2046: Quote this to prevent word splitting.
                       ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                       ^-- SC2006: Use $(..) instead of legacy `..`.
                       ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                             ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 217:
             CacheRedisSock=$(cat `echo $LocalXML` 2> /dev/null| grep Cache_Backend_Redis -A13| grep "<server>"| uniq| cut -d ">" -f2|cut -d "<" -f1| cut -d "." -f2)
                                  ^-- SC2046: Quote this to prevent word splitting.
                                  ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                                  ^-- SC2006: Use $(..) instead of legacy `..`.
                                  ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                        ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 221:
  CacheRedisPorts=$(cat `echo $LocalXML` 2> /dev/null| grep Cache_Backend_Redis -A13| cut -d '>' -f2| grep port | cut -d '<' -f1|uniq)
                        ^-- SC2046: Quote this to prevent word splitting.
                        ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                        ^-- SC2006: Use $(..) instead of legacy `..`.
                        ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                              ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 223:
           CacheRedisPorts=$(cat `echo $LocalXML 2> /dev/null` |grep Cache_Backend_Redis -A13 | grep port | cut -d "[" -f3| cut -d "]" -f1| grep -Ev "gzip"|uniq)
                                 ^-- SC2046: Quote this to prevent word splitting.
                                 ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                                 ^-- SC2006: Use $(..) instead of legacy `..`.
                                 ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 232:
  CacheRedisDB=$(cat `echo $LocalXML` 2> /dev/null| grep Cache_Backend_Redis -A13 | grep database | cut -d ">" -f2 |cut -d "<" -f1|uniq)
                     ^-- SC2046: Quote this to prevent word splitting.
                     ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                     ^-- SC2006: Use $(..) instead of legacy `..`.
                     ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                           ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 237:
      echo "CacheRedisIPs: `echo $CacheRedisIP 2> /dev/null`";
                           ^-- SC2006: Use $(..) instead of legacy `..`.
                           ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                 ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 241:
          echo "redis-cli -s `echo $CacheRedisIP` flushall";
                             ^-- SC2006: Use $(..) instead of legacy `..`.
                             ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 242:
          echo 'flushall' | redis-cli -s `echo $CacheRedisIP`;
                                         ^-- SC2046: Quote this to prevent word splitting.
                                         ^-- SC2006: Use $(..) instead of legacy `..`.
                                         ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                               ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 245:
       for ICacheRedisIP in `echo $CacheRedisIP|xargs -I{} -n1 echo {}` ; do
                            ^-- SC2006: Use $(..) instead of legacy `..`.
                                  ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 246:
            for ICacheRedisPorts in `echo $CacheRedisPorts|xargs -I{} -n1 echo {}` ; do
                                    ^-- SC2006: Use $(..) instead of legacy `..`.
                                          ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 247:
                echo "Cache-redis-ports: `echo $CacheRedisPorts 2> /dev/null`";
                                         ^-- SC2006: Use $(..) instead of legacy `..`.
                                         ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                               ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 251:
                            if [ -n "`whereis redis-cli| awk '{print $2}'`" ]; then
                                     ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 252:
                                  R_flush=$(redis-cli -h `echo $ICacheRedisIP` -p `echo $ICacheRedisPorts` flushall)
                                  ^-- SC2034: R_flush appears unused. Verify it or export it.
                                                         ^-- SC2046: Quote this to prevent word splitting.
                                                         ^-- SC2006: Use $(..) instead of legacy `..`.
                                                         ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                               ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                                  ^-- SC2046: Quote this to prevent word splitting.
                                                                                  ^-- SC2006: Use $(..) instead of legacy `..`.
                                                                                  ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                                                        ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 254:
                                  echo "redis-cli -h `echo $ICacheRedisIP` -p `echo $ICacheRedisPorts` flushall";
                                                     ^-- SC2006: Use $(..) instead of legacy `..`.
                                                     ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                           ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                              ^-- SC2006: Use $(..) instead of legacy `..`.
                                                                              ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                                                    ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 260:
                                  echo $ICacheRedisIP '+' $ICacheRedisPorts
                                       ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                          ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 272:
                            echo "CacheRedisDB = `echo $CacheRedisDB 2> /dev/null`"
                                                 ^-- SC2006: Use $(..) instead of legacy `..`.
                                                 ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 275:
                            Server_port="SERVER::::> `echo $ICacheRedisIP` PORT::::> `echo $ICacheRedisPorts`";
                                                     ^-- SC2006: Use $(..) instead of legacy `..`.
                                                     ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                           ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                                     ^-- SC2006: Use $(..) instead of legacy `..`.
                                                                                     ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                                                           ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 277:
                            echo "`echo $Server_port`";
                                 ^-- SC2005: Useless echo? Instead of 'echo $(cmd)', just use 'cmd'.
                                  ^-- SC2006: Use $(..) instead of legacy `..`.
                                  ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                        ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 278:
                            for ICacheRedisDB in `echo $CacheRedisDB|xargs -I{} -n1 echo {}` ; do
                                                 ^-- SC2006: Use $(..) instead of legacy `..`.
                                                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 281:
                                echo "`echo $Server_port` DataBase::::> `echo $ICacheRedisDB`";
                                      ^-- SC2006: Use $(..) instead of legacy `..`.
                                      ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                            ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                                        ^-- SC2006: Use $(..) instead of legacy `..`.
                                                                        ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                                              ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 283:
                                CacheRedisDBAuth=$(cat `echo $LocalXML` 2> /dev/null| grep Cache_Backend_Redis -A13 | grep password | cut -d ">" -f2 |cut -d "<" -f1|uniq)
                                                       ^-- SC2046: Quote this to prevent word splitting.
                                                       ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                                                       ^-- SC2006: Use $(..) instead of legacy `..`.
                                                       ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                                             ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 304:
                                      for ICacheRedisDBAuth in `echo $CacheRedisDBAuth|xargs -I{} -n1 echo {}` ; do
                                                               ^-- SC2006: Use $(..) instead of legacy `..`.
                                                                     ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 340:
     echo "Local Cache on server `hostname`";
                                 ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 344:
          `rm -rf echo $Cache_Dir`
          ^-- SC2092: Remove backticks to avoid executing output.
          ^-- SC2006: Use $(..) instead of legacy `..`.
                       ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 359:
        MemcachedServer=$(cat `echo $LocalXML` 2> /dev/null | grep -Ev ^$| grep '<memcached>' -A7| grep -E 'host|CDATA|port' | grep -v "ersistent"| grep host| cut -d "[" -f3| cut -d "]" -f1|uniq)
                              ^-- SC2046: Quote this to prevent word splitting.
                              ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                              ^-- SC2006: Use $(..) instead of legacy `..`.
                              ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                    ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 360:
        MemcachedPort=$(cat `echo $LocalXML` 2> /dev/null | grep -Ev ^$| grep '<memcached>' -A7| grep -E 'host|CDATA|port' | grep -v "ersistent"| grep port| cut -d "[" -f3| cut -d "]" -f1|uniq)
                            ^-- SC2046: Quote this to prevent word splitting.
                            ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
                            ^-- SC2006: Use $(..) instead of legacy `..`.
                            ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                  ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 366:
              echo "Memcached Server => `echo $MemcachedServer`";
                                        ^-- SC2006: Use $(..) instead of legacy `..`.
                                        ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                              ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 367:
              echo "Memcached Port => `echo $MemcachedPort`";
                                      ^-- SC2006: Use $(..) instead of legacy `..`.
                                      ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                            ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 369:
              `which expect | grep -E expect` <<EOF
              ^-- SC2092: Remove backticks to avoid executing output.
              ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 378:
              echo "memcached has been flushed on server `hostname`";
                                                         ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 382:
              echo "Din't find memcached on server `hostname`";
                                                   ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 391:
for IRootFolder in `cat $RootFolder|xargs -I{} -n1 echo {}` ; do
                   ^-- SC2006: Use $(..) instead of legacy `..`.
                        ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.


In flush-cache.sh line 393:
        echo " ~~~~~~ `echo $SITE` ~~~~~~ ";
                      ^-- SC2006: Use $(..) instead of legacy `..`.
                      ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                            ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 402:
               echo "Root-XML with '/' : `echo $LocalXML| grep -vE "DocumentRoot"`";
                                         ^-- SC2006: Use $(..) instead of legacy `..`.
                                               ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 412:
                echo "Root-XML: `echo $LocalXML`";
                                ^-- SC2006: Use $(..) instead of legacy `..`.
                                ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
                                      ^-- SC2086: Double quote to prevent globbing and word splitting.


In flush-cache.sh line 422:
mail -s " HOSTNAME is `hostname`" $List_of_emails < $FlushCacheReport
                      ^-- SC2006: Use $(..) instead of legacy `..`.


In flush-cache.sh line 423:
if [ $? -eq 0 ]; then
     ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.


In flush-cache.sh line 425:
      echo "LOG_FILE= $FlushCacheReport has been sent to `echo $List_of_emails`";
                                                         ^-- SC2006: Use $(..) instead of legacy `..`.
                                                         ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.


In flush-cache.sh line 429:
      echo "The email hasn't been sent to `echo $List_of_emails`";
                                          ^-- SC2006: Use $(..) instead of legacy `..`.
                                          ^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.

Утилита поможет отладить ваши баш-скрипты помогая советами (как видно с вывода моего скрипта).

Интеграция ShellCheck в текстовый редактор

ShellCheck позоляет произвести интеграцию с некоторыми текстовыми редакторами (vim, emacs). Он может проверять ваш код прямо в текстовом редакторе. Для этого стоит установить:

  • pearofducks/ansible-vim
  • neomake/neomake

Давайте установим эти плагины для vim, открываем:

# vim ~/.vimrc

Прописываем:

call plug#begin('~/.vim/autoload')
Plug 'pearofducks/ansible-vim'
Plug 'pearofducks/ansible-vim', { 'do': './UltiSnips/generate.py' }
Plug 'neomake/neomake'
call plug#end()

Чтобы установить плагины, откройте редактор вим, и в нем введите:

:PlugInstall

Теперь, открываем любой плагин и вводим:

:Neomake

Получаем подсказки.

На этом у меня все, статья «Установка ShellCheck в Unix/Linux » подошла к завершению.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Этот сайт использует Akismet для борьбы со спамом. Узнайте, как обрабатываются ваши данные комментариев.