Skip to content

Shebang wrapper runs script if `shellcheck` returns no errors

License

Notifications You must be signed in to change notification settings

paranoid-linux/shellchecker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shellchecker

Shebang wrapper runs script if shellcheck returns no errors

Byte size of Shellchecker Open Issues Open Pull Requests Latest commits Build Status



Requirements

Install via the package manager for your distribution; gawk, make, and shellcheck, packages that this repository depends upon...

  • Arch based Operating Systems
sudo packman -Syy

sudo packman -S gwak make shellcheck
  • Debian derived Operating Systems...
sudo apt-get update

sudo apt-get install gawk make shellcheck

Additionally the shellchecker script is tested and written for Bash version 4.4; please ensure that this version, or greater, is installed on your device prior to opening new bug related Issues.


Quick Start

Clone this project to a root owned directory...

Linux/MacOS

cd /usr/local/etc

sudo git clone [email protected]:paranoid-linux/shellchecker.git

Install via make...

cd /usr/local/etc/shellchecker

sudo make install

Uninstall/unlink via make...

cd /usr/local/etc/shellchecker

sudo make uninstall

Upgrade/update via git...

cd /usr/local/etc/shellchecker

sudo git pull

Usage

Write a script that uses /usr/local/sbin/shellchecker as the shebang...

example.sh

#!/usr/local/sbin/shellchecker --format=gcc bash --restricted

_argument_list=("${@}")
for i in "${!_argument_list[@]}"; do
    printf '_argument_list[%i] -> %s\n' "${i}" "${_argument_list[${i}]}"
done

Provide executable permissions and run example.sh script...

chmod u+x ./example.sh


./example.sh

Append an error producing line and attempt to re-run the example.sh script...

tee -a ./example.sh 1>/dev/null <<EOF
echo "${_noOpp}"
EOF


./example.sh

Output should be similar to...

./example.sh:8:7: warning: _noOpp is referenced but not assigned. [SC2154]

Notes

This repository may not be feature complete and/or fully functional, Pull Requests that add features or fix bugs are certainly welcomed.


Compatible Shells

The shellchecker shebang wrapper script should be compatible with shells that the shellcheck package supports;

  • bash

  • dash

  • ksh

  • sh


Environment Variables

Setting SHELLCHECKER_VERBOSE environment variable to any number greater than 0 will enable printing commands to standard error, eg...

SHELLCHECKER_VERBOSE=1 ./example.sh

Return Values

ShellCheck uses the follow exit codes:

  • 0: All files successfully scanned with no issues.

  • 1: All files successfully scanned with some issues.

  • 2: Some files could not be processed (e.g. file not found).

  • 3: ShellCheck was invoked with bad syntax (e.g. unknown flag).

  • 4: ShellCheck was invoked with bad options (e.g. unknown formatter).

Check man shellcheck for more information.


Contributing

Options for contributing to shellchecker and paranoid-linux


Forking

Start making a Fork of this repository to an account that you have write permissions for.

cd ~/git/hub/paranoid-linux/shellchecker

git remote add fork [email protected]:<NAME>/shellchecker.git
  • Commit your changes and push to your fork, eg. to fix an issue...
cd ~/git/hub/paranoid-linux/shellchecker


git commit -F- <<'EOF'
:bug: Fixes #42 Issue


**Edits**


- `<SCRIPT-NAME>` script, fixes some bug reported in issue
EOF


git push fork main

Note, the -u option may be used to set fork as the default remote, eg. git push fork main however, this will also default the fork remote for pulling from too! Meaning that pulling updates from origin must be done explicitly, eg. git pull origin main

  • Then on GitHub submit a Pull Request through the Web-UI, the URL syntax is https://github.com/<NAME>/<REPO>/pull/new/<BRANCH>

Note; to decrease the chances of your Pull Request needing modifications before being accepted, please check the dot-github repository for detailed contributing guidelines.


Sponsor

Thanks for even considering it!

Via Liberapay you may sponsor__shields_io__liberapay on a repeating basis.

Regardless of if you're able to financially support projects such as shellchecker that paranoid-linux maintains, please consider sharing projects that are useful with others, because one of the goals of maintaining Open Source repositories is to provide value to the community.


Attribution


License

Shebang wrapper runs script if `shellcheck` returns no errors
Copyright (C) 2020 S0AndS0

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

For further details review full length version of AGPL-3.0 License.

About

Shebang wrapper runs script if `shellcheck` returns no errors

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project