Skip to content

Shellcheck: Check directories recursively

In this post, you will learn how to use the ShellCheck tool to scan your shell/bash script directories recursively.

ShellCheck is a shell script static analysis tool, it gives warnings and suggestions for bash/sh shell scripts.

Official ShellCheck page.

you can download pre-compiled binaries for the GitHub page. Under the installation section, you will find the OS-specific pre-complied binaries.

Since we are going to run this on windows OS. I have downloaded it at: https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.zip

After downloading unzip it and add it to the path environment so that you can use the spellcheck command anywhere in the system. otherwise, you have to give the full path to access it (see the below example, it has a full path)

PowerShell script to check directories recursively for .sh files, then give file path to Shellcheck tool and write output to the file.

$path = "D:\linux-scripts\";
Get-ChildItem -Path $path -Filter *.sh -Recurse | ForEach-Object {
    Write-Host "checking:: $_.FullName"
    $Response = C:\shellcheck-stable\shellcheck.exe --format=gcc $_.FullName 
    Add-Content ./scan-report.txt ($Response)
    Write-Host "Done!!!"
}
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments