Linting
Clean your bash code. Seriously. Saves so much time in the long run.
The default pre-commit hook for .sh files will run bashSanitize on your code. To avoid or
skip directories, create ./etc/bashSanitize.conf and add file paths to exclude.
bashSanitize
Sanitize bash files for code quality.
Usage
bashSanitize [ --help ] [ -- ] [ --home home ] [ --interactive ] [ --check checkDirectory ] [ ... ]
Sanitize bash files for code quality.
used in find find ... ! -path '*LINE*' and in grep -e 'LINE'
TODO - use one mechanism for bashSanitize.conf format
Arguments
--help- Flag. Optional. Display this help.--- Flag. Optional. Interactive mode on fixing errors.--home home- Directory. Optional. Sanitize files starting here. (Defaults tobuildHome)--interactive- Flag. Optional. Interactive mode on fixing errors.--check checkDirectory- Directory. Optional. Check shell scripts in this directory for common errors....- Additional arguments are passed tobashLintFilesvalidateFileContents
Return codes
0- Success1- Environment error2- Argument error
bashLintFiles
Check files for the existence of a string
Usage
bashLintFiles [ --verbose ] [ --fix ] [ --interactive ] [ --exec binary ] [ --delay ] [ findArgs ]
Run bashLint on a set of bash files.
Arguments
--verbose- Flag. Optional. Verbose mode.--fix- Flag. Optional. Fix errors when possible.--interactive- Flag. Optional. Interactive mode on fixing errors.--exec binary- Run binary with files as an argument for any failed files. Only works if you pass in item names.--delay- Integer. Optional. Delay between checks in interactive mode.findArgs- Additional find arguments for .sh files (or exclude directories).
Examples
if bashLintFiles; then git commit -m "saving things" -a; fi
Sample Output
This outputs statusMessages to stdout and errors to stderr.
Return codes
0- All found files passshellcheckandbash -n1- One or more files did not pass
Environment
- This operates in the current working directory
bashLintFilesInteractive
Run checks interactively until errors are all fixed.
Usage
bashLintFilesInteractive [ --exec binary ] [ --delay delaySeconds ] [ fileToCheck ... ]
Run checks interactively until errors are all fixed.
Arguments
--exec binary- Callable. Optional. Run binary with files as an argument for any failed files. Only works if you pass in item names.--delay delaySeconds- Integer. Optional. Delay in seconds between checks in interactive mode.fileToCheck ...- File. Optional. Shell file to validate.
Return codes
0- Success1- Environment error2- Argument error
bashLint
Check bash files for common errors
Usage
bashLint [ --help ] [ --fix ] [ --verbose ] [ script ]
Run shellcheck and bash -n on a set of bash files.
This can be run on any directory tree to test scripts in any application.
Shell comments must not be immediately after a function end, e.g. this is invalid:
myFunc() {
}
# Hey
Arguments
--help- Flag. Optional. Display this help.--fix- Flag. Optional. Fix files when possible.--verbose- Flag. Optional. Be verbose.script- File. Optional. Shell script to validate
Examples
bashLint goo.sh
Sample Output
This outputs statusMessages to stdout and errors to stderr.
Return codes
0- All found files passshellcheckandbash -nand shell comment syntax1- One or more files did not pass