LoginHelp/GuideAbout TracPreferences
WikiTimelineRoadmapBrowse SourceView TicketsNew TicketSearchDownloads

bashcritic

bashcritic is a tool to check shell scripts for common pitfalls

bashcritic is in alpha stage: I would appreciate comments as well as suggestions on what could be checked (in addition to the implemented tests)

Mail any critique, comment or suggestion to matteo.corti@… or post them in the  ticket section

Download

You can get a tarball with the latest alpha in the  downloads section or download the source with subversion:  https://svn.id.ethz.ch/bashcritic.

News

  • 2008-01-31: version 0.3.3 (alpha): corrected a syntax error in a check rule (#39)
  • 2008-01-30: version 0.3.2 (alpha): some new rules, less error levels and automatic shell detection. See the change log for more details.
  • 2007-10-20: version 0.3.0 (alpha): some new rules (#11, #15, #18 and #22), does not process comments and strings (#3) and some minor fixes (#32). See the change log for more details.
  • 2007-10-18: version 0.2.1 (alpha): bug fix release (r27 fixes a program crash due to an error in a rule definition)
  • 2007-10-17: version 0.2.0 (alpha): several improvements and corrections (mainly from  comp.unix.shell)

Usage

Usage:
      bashcritic [-012 | --info | --cosmetic | --error]
                 [--posix | --bourne]
                 [--severity number]
                 [--ignore_shebang ]
                 [--list [format]]
                 [-verbose ]
                 {FILE | STDIN}

      Options:

        --error,-e,-0        report only errors
        --cosmetic,-c,-1     report errors and cosmetic problems
        --info,-i,2          report error, cosmetic problems and minor issues

        --posix              script should be POSIX compliant
        --bourne             script should be Bourne shell compatible

        --list [format]      lists implemented tests (formats: trac)

        --ignore-shebang     ignores the script shebang
        --[no-]color         colorize output

        --help,-h,-?         prints this help message
        
        --verbose,-v         increase verbosity
        --version,-V         prints program version and exits

Tests

bashcritic 0.3.2 checks for the following problems and pitfalls:

DescriptionSeverityApplies to
Line is longer than 80 characters, consider splitting it over multiple lines to increase readability.INFOPOSIX
"declare keyword" is not portable use subshells (...) or $(...) to define local variables (or variables with special attributes).ERRORPOSIX
"let" is ksh-specific, use the $((...)) POSIX form instead.ERRORPOSIX
"select" is ksh, bash and zsh specific. Use printd and read instead.ERRORBOURNE, CSH, POSIX, TCSH
"source FILE" is not portable use ". FILE" instead.ERRORPOSIX
"typeset keyword" is not portable use subshells (...) or $(...) to define local variables (or variables with special attributes).ERRORPOSIX
$'...' is ksh93, bash and zsh specific, use printf %b insteadERRORBOURNE, CSH, POSIX, TCSH
$((...)) is POSIX but not BourneERRORBOURNE
$RANDOM is bash/ksh/zsh specific. Use awk's rand() for randomness.ERRORBOURNE, CSH, POSIX, TCSH
Avoid $SECONDS: is bash/ksh/zsh specific.ERRORBOURNE, CSH, POSIX, TCSH
Avoid here-strings (a special form of the here-document) in portable scripts.ERRORBASH, BOURNE, CSH, KSH, POSIX, TCSH, ZSH
Bourne shell does not provile tilde expansionERRORBOURNE
Bourne shell does not support the POSIX-form $(COMMANDS), use COMMANDS instead.ERRORBOURNE
Export behaves differently depending on the shell (e.g., 'a="A B"; export b=$a' exports b as "A B" on bash AT&T ksh making them non-POSIX compliantERRORBASH, BOURNE, CSH, KSH, POSIX, TCSH, ZSH
Some (older) systems do not allow shebangs longer than 32 bytesERRORBASH, BOURNE, CSH, KSH, POSIX, TCSH, ZSH
The "[[" test keyword is reserved by POSIX, but not defined. Use "test" or "[" insteadERRORPOSIX
The "function NAME" form of the function definition is ksh-specific simply use "NAME()" to define a function.ERRORPOSIX
The $[EXPRESSION] syntax is completely replaced by the POSIX-conform arithmetic expansion $((EXPRESSION)).ERRORPOSIX
The &>FILE redirection syntax is not part of POSIX, use >FILE 2>&1 insteadERRORPOSIX
Though POSIX allows it, bourne shell don't want the assignment and the exporting in one command.ERRORBOURNE
alias is not supported by Bourne shellERRORBOURNE
command is not supported by Bourne shellERRORBOURNE
readonly is not supported by Bourne shellERRORBOURNE
unset is not supported by every Bash shellERRORBOURNE

Documentation

Short list of documents and resources that has to be checked for rules

See also

 

Wichtiger Hinweis:
Diese Website wird in älteren Versionen von Netscape ohne graphische Elemente dargestellt. Die Funktionalität der Website ist aber trotzdem gewährleistet. Wenn Sie diese Website regelmässig benutzen, empfehlen wir Ihnen, auf Ihrem Computer einen aktuellen Browser zu installieren. Weitere Informationen finden Sie auf
folgender Seite.

Important Note:
The content in this site is accessible to any browser or Internet device, however, some graphics will display correctly only in the newer versions of Netscape. To get the most out of our site we suggest you upgrade to the newer browser.
More information

 
© 2005 ETH Zürich | Imprint | 26.09.2007 | Version 0.12
top