Linux : ShellCheck pour analyser vos scripts bash

De www.yakakliker.org

ShellCheck

  • Shellcheck est un utilitaire qui va analyser votre script afin de déceler les erreurs.

Installation

apt-get install shellcheck

Analyse d'un script

shellcheck monscript.sh

Exemple de réponse

In Services.sh line 11:
cd ~
^--^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Did you mean:
cd ~ || exit


In Services.sh line 22:
cd /home
^------^ SC2164 (warning): Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

Did you mean:
cd /home || exit


In Services.sh line 24:
echo $env00 >> ~/env.txt
     ^----^ SC2086 (info): Double quote to prevent globbing and word splitting.

Did you mean:
echo "$env00" >> ~/env.txt


In Services.sh line 35:
export var24051101=`date +%y%m%d`
       ^---------^ SC2155 (warning): Declare and assign separately to avoid masking return values.
                   ^------------^ SC2006 (style): Use $(...) notation instead of legacy backticks `...`.

Did you mean:
export var24051101=$(date +%y%m%d)

Liens

https://blog.stephane-robert.info/docs/admin-serveurs/linux/scripts-shell-securises/


compteur web gratuit sans pub