centos7中安装Shellcheck

目录

 

一、安装shellcheck

二、使用shellcheck

三、使用shellcheck检测

四、官方说明网站


一、安装shellcheck


!!!由于发现网上各种复制粘贴,而且安装繁琐,特此写个博客,请转载着附上原网站。

#安装扩展源

yum -y install epel-release

#安装shellcheck

yum install ShellCheck

#提示安装成功如下

Installed:
  ShellCheck.x86_64 0:0.3.8-1.el7                                                                                                                                           

Dependency Installed:
  ghc-ShellCheck.x86_64 0:0.3.8-1.el7        ghc-array.x86_64 0:0.4.0.1-26.4.el7     ghc-base.x86_64 0:4.6.0.1-26.4.el7         ghc-bytestring.x86_64 0:0.10.0.2-26.4.el7  
  ghc-containers.x86_64 0:0.5.0.0-26.4.el7   ghc-deepseq.x86_64 0:1.3.0.1-26.4.el7   ghc-directory.x86_64 0:1.2.0.1-26.4.el7    ghc-filepath.x86_64 0:1.3.0.1-26.4.el7     
  ghc-json.x86_64 0:0.7-4.el7                ghc-mtl.x86_64 0:2.1.2-27.el7           ghc-old-locale.x86_64 0:1.0.0.5-26.4.el7   ghc-parsec.x86_64 0:3.1.3-31.el7           
  ghc-pretty.x86_64 0:1.1.1.0-26.4.el7       ghc-regex-base.x86_64 0:0.93.2-29.el7   ghc-regex-tdfa.x86_64 0:1.1.8-11.el7       ghc-syb.x86_64 0:0.4.0-35.el7              
  ghc-text.x86_64 0:0.11.3.1-2.el7           ghc-time.x86_64 0:1.4.0.1-26.4.el7      ghc-transformers.x86_64 0:0.3.0.0-34.el7   ghc-unix.x86_64 0:2.6.0.1-26.4.el7    

 


二、使用shellcheck


测试

vim test.txt

#!/bin/sh
for n in {1..$RANDOM}
do
  str=""
  if (( n % 3 == 0 ))
  then
    str="fizz"
  fi
  if [ $[n%5] == 0 ]
  then
    str="$strbuzz"
  fi
  if [[ ! $str ]]
  then
    str="$n"
  fi
  echo "$str"
done

 


三、使用shellcheck检测


[root@nacos ~]# shellcheck jia.sh 

In jia.sh line 2:
for n in {1..$RANDOM}
         ^-- SC2039: In POSIX sh, brace expansion is not supported.
             ^-- SC2039: In POSIX sh, RANDOM is not supported.


In jia.sh line 5:
  if (( n % 3 == 0 ))
     ^-- SC2039: In POSIX sh, standalone ((..)) is not supported.


In jia.sh line 9:
  if [ $[n%5] == 0 ]
       ^-- SC2039: In POSIX sh, $[..] in place of $((..)) is not supported.
       ^-- SC2007: Use $((..)) instead of deprecated $[..]
              ^-- SC2039: In POSIX sh, == is not supported.


In jia.sh line 11:
    str="$strbuzz"
         ^-- SC2154: strbuzz is referenced but not assigned.


In jia.sh line 13:
  if [[ ! $str ]]
     ^-- SC2039: In POSIX sh, [[ ]] is not supported.

此时说明shellcheck可以使用

 


四、官方说明网站


https://github.com/koalaman/shellcheck

https://github.com/koalaman/shellcheck/tree/v0.7.1#installing

 

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

烟雨话浮生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值