Update README.md

This commit is contained in:
koalaman 2016-12-30 10:31:34 -08:00 committed by GitHub
parent 30e94ea7ab
commit 6f5648faca

View file

@ -54,7 +54,7 @@ You can see ShellCheck suggestions directly in a variety of editors.
#### In your build or test suites #### In your build or test suites
While ShellCheck is mostly intended for interactive use, it can easily be added to builds or test suites. While ShellCheck is mostly intended for interactive use, it can easily be added to builds or test suites.
Use ShellCheck's exit code, or its [CheckStyle compatible XML output](shellcheck.1.md#user-content-formats). There's also a simple JSON output format for easy integration. ShellCheck makes canonical use of exit codes, and can output simple JSON, CheckStyle compatible XML, GCC compatible warnings as well as human readable text (with or without ANSI colors). See the [Integration](https://github.com/koalaman/shellcheck/wiki/Integration) wiki page for more documentation.
## Installing ## Installing
@ -99,6 +99,9 @@ add OBS devel:languages:haskell repository from https://build.opensuse.org/proje
or use OneClickInstall - https://software.opensuse.org/package/ShellCheck or use OneClickInstall - https://software.opensuse.org/package/ShellCheck
From Docker Hub:
docker pull koalaman/shellcheck
## Compiling from source ## Compiling from source
@ -183,6 +186,8 @@ ShellCheck can recognize many types of incorrect test statements.
[ $1 -eq "shellcheck" ] # Numerical comparison of strings [ $1 -eq "shellcheck" ] # Numerical comparison of strings
[ $n && $m ] # && in [ .. ] [ $n && $m ] # && in [ .. ]
[ grep -q foo file ] # Command without $(..) [ grep -q foo file ] # Command without $(..)
[[ "$$file" == *.jpg ]] # Comparisons that can't succeed
(( 1 -lt 2 )) # Using test operators in ((..))
#### Frequently misused commands #### Frequently misused commands
@ -211,9 +216,11 @@ ShellCheck recognizes many common beginner's syntax errors:
var$n="Hello" # Wrong indirect assignment var$n="Hello" # Wrong indirect assignment
echo ${var$n} # Wrong indirect reference echo ${var$n} # Wrong indirect reference
var=(1, 2, 3) # Comma separated arrays var=(1, 2, 3) # Comma separated arrays
array=( [index] = value ) # Incorrect index initialization
echo "Argument 10 is $10" # Positional parameter misreference echo "Argument 10 is $10" # Positional parameter misreference
if $(myfunction); then ..; fi # Wrapping commands in $() if $(myfunction); then ..; fi # Wrapping commands in $()
else if othercondition; then .. # Using 'else if' else if othercondition; then .. # Using 'else if'
#### Style #### Style
@ -236,7 +243,8 @@ ShellCheck can recognize issues related to data and typing:
args="$@" # Assigning arrays to strings args="$@" # Assigning arrays to strings
files=(foo bar); echo "$files" # Referencing arrays as strings files=(foo bar); echo "$files" # Referencing arrays as strings
printf "%s\n" "Arguments: $@." # Concatenating strings and arrays. declare -A arr=(foo bar) # Associative arrays without index
printf "%s\n" "Arguments: $@." # Concatenating strings and arrays
[[ $# > 2 ]] # Comparing numbers as strings [[ $# > 2 ]] # Comparing numbers as strings
var=World; echo "Hello " var # Unused lowercase variables var=World; echo "Hello " var # Unused lowercase variables
echo "Hello $name" # Unassigned lowercase variables echo "Hello $name" # Unassigned lowercase variables
@ -269,6 +277,7 @@ ShellCheck will warn when using features not supported by the shebang. For examp
foo-bar() { ..; } # Undefined/unsupported function name foo-bar() { ..; } # Undefined/unsupported function name
[ $UID = 0 ] # Variable undefined in dash/sh [ $UID = 0 ] # Variable undefined in dash/sh
local var=value # local is undefined in sh local var=value # local is undefined in sh
time sleep 1 | sleep 5 # Undefined uses of 'time'
#### Miscellaneous #### Miscellaneous
@ -279,11 +288,13 @@ ShellCheck recognizes a menagerie of other issues:
PATH="$PATH:~/bin" # Literal tilde in $PATH PATH="$PATH:~/bin" # Literal tilde in $PATH
rm “file” # Unicode quotes rm “file” # Unicode quotes
echo "Hello world" # Carriage return / DOS line endings echo "Hello world" # Carriage return / DOS line endings
echo hello \ # Trailing spaces after \
var=42 echo $var # Expansion of inlined environment var=42 echo $var # Expansion of inlined environment
#!/bin/bash -x -e # Common shebang errors #!/bin/bash -x -e # Common shebang errors
echo $((n/180*100)) # Unnecessary loss of precision echo $((n/180*100)) # Unnecessary loss of precision
ls *[:digit:].txt # Bad character class globs ls *[:digit:].txt # Bad character class globs
sed 's/foo/bar/' file > file # Redirecting to input sed 's/foo/bar/' file > file # Redirecting to input
## Testimonials ## Testimonials