1001
This \\N will be a regular 'N' in this context.
Bash, zsh, ksh: regardless what Shell you use, Codiga got you covered. With hundreds of rules, the Codiga Static Engine checks for any issue in your shell script and surfaces issues in your Shell codebase.
This \\N will be a regular 'N' in this context.
Want to escape a single quote? echo 'This is how it'\\''s done'.
This backslash+linefeed is literal. Break outside single quotes if you just want to break the line.
Remove space after = if trying to assign a value (for empty string
This shebang was unrecognized. Note that ShellCheck only handles sh/bash/dash/ksh.
The mentioned syntax error was in this elif clause.
Use semicolon or linefeed before 'fi' (or quote to make it literal).
\\r is just literal 'r' here. For carriage return
Use 'if cmd; then ..' to check exit code
Literal carriage return. Run script through tr -d '\\r' .
This is a unicode non-breaking space. Delete and retype it.
Expected this to be an argument to the unary condition.
You need a space before the ]].
You are missing a required space after the !.
(' is invalid here. Did you forget to escape it?
Couldn't find 'fi' for this 'if'.
Expected 'fi' matching previously mentioned 'if'.
Can't have empty else clauses (use 'true' as a no-op).
Did you forget the 'then' for this 'if'?
Expected 'then'.
You need a space after the '{'.
You need at least one command here. Use 'true;' as a no-op.
Expected a '}'. If you have one
Expected 'do'.
Couldn't find 'done' for this 'do'.
Expected 'done' matching previously mentioned 'do'.
Expected a { to open the function definition.
Trying to declare parameters? Don't. Use () and refer to params as $1
Don't use $ on the left side of assignments.
Don't put spaces around the = in assignments (or quote to make it literal).
Parsing stopped here. Mismatched keywords or invalid parentheses?
ShellCheck only supports sh/bash/dash/ksh scripts. Sorry!
Expected 'then'. Fix any mentioned problems and try again.
Couldn't parse this escaped char. Fix to allow more checks.
Use 'elif' instead of 'else if' (or put 'if' on new line if nesting).
Did you forget to close this double quoted string?
This is actually an end quote
You need \\ before line feeds to break lines in [ ].
This file has a UTF-8 BOM. Remove it with: LC\_CTYPE=C sed '1s/^...//' < yourscript .
This } is literal. Check expression (missing ;/\\n?) or quote it.
Use #! and not !# for shebang
Don't use $ on the iterator name in for loops.
Use braces when expanding arrays
Parsing stopped here. Invalid use of parentheses?
Parsing stopped here. Is this keyword correctly matched up?
Can't follow non-constant source. Use a directive to specify location.
Not following: /etc/os-release was not specified as input (see shellcheck -x).
You need a space or linefeed between the function name and body.
Unexpected ==. For assignment
You need a space before the #.
Delete trailing spaces after \\ to break line (or use quotes for literal space).
Shells disambiguate $(( differently or not at all. For $(command substition)
Use #! and not ! for shebang
Shells disambiguate (( differently or not at all. For subshell
This is a unicode quote. Delete and retype it (or quote to make literal).
This is a unicode quote. Delete and retype it (or ignore/singlequote for literal).
Use #! for the shebang
Remove leading spaces before the shebang.
Remove spaces between # and ! in the shebang.
Missing $ on a $((..)) expression? (or use ( ( for arrays).
Backslash is literal in \\’". Prefer explicit escaping: "\\\\’"."
Add a linefeed between end token and terminating ')'.
Place shellcheck directives before commands
Was this intended as a comment? Use # in sh.
The shebang must be on the first line. Delete blanks and move comments.
See if you can use ${#variable} instead.
See if you can use ${variable//search/replace} instead.
Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
expr is antiquated. Consider rewriting this using $((..))
$/${} is unnecessary on arithmetic variables.
Useless echo? Instead of 'echo $(cmd)'
Use $(...) notation instead of legacy backticked `...`.
Use $((..)) instead of deprecated $[..]
Consider using pgrep instead of grepping ps output.
Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
Use 'find .. -print0 | xargs -0 ..' or 'find .. -exec .. +' to allow non-alphanumeric filenames.
Use find instead of ls to better handle non-alphanumeric filenames.
To read lines rather than words
This will expand once before find runs
Note that A && B || C is not if-then-else. C may run when A is true.
Expressions don't expand in single quotes
Increase precision by replacing a/b*c with a*c/b.
Use '[:lower:]' to support accents and foreign alphabets.
Use '[:upper:]' to support accents and foreign alphabets.
tr replaces sets of chars
Don't use [] around classes in tr
Note that unlike globs
The shell may override 'time' as seen in man time(1). Use 'command time ..' for that one.
sudo doesn't affect redirects. Use sudo cat file | ..
This word is outside of quotes. Did you intend to 'nest ''single quotes'"' instead'? "
The surrounding quotes actually unquote this. Remove or escape them.
echo won't expand escape sequences. Consider printf.
Expansion on the client side
Modification of RSYSLOG\_VERSION is local (to subshell caused by pipeline).
RSYSLOG\_VERSION was modified in a subshell. That change might be lost.
Use own script or sh -c '..' to run this from sudo.
Shell functions can't be passed to external commands.
Variable appears unused. Verify use (or export if used externally).
Use ./*glob* or -- *glob* so names with dashes won't become options.
If you wanted to assign the output of the pipeline
Use -print0/-0 or -exec + to allow for non-alphanumeric filenames.
Undefined keyword for POSIX sh
This loop will only ever run once for a constant value. Did you perhaps mean to loop over dir/*
For loops over find output are fragile. Use find -exec or a while read loop.
Iterating over ls output is fragile. Use globs.
Quote this to prevent word splitting.
Use $@" (with quotes) to prevent whitespace problems."
"=~ is for regex, but this looks like a glob. Use = instead."
This expression is constant. Did you forget the $ on a variable?
Quote the right-hand side of != in [[ ]] to prevent glob matching.
Don't use variables in the printf format string. Use printf ..\%s.." "$foo"."
Quote parameters to tr to prevent glob expansion.
Quote the parameter to -iname so the shell won't interpret it.
Quote the grep pattern so the shell won't interpret it.
Grep uses regex
Use single quotes
Since you double quoted this
Missing ';' or + terminating -exec. You can't use |/||/&&
Double quote array expansions to avoid re-splitting elements.
To redirect stdout+stderr
-n doesn't work with unquoted arguments. Quote or use [[ ]].
> is for string comparisons. Use -gt instead.
Decimals are not supported. Either use integers only
Don't quote rhs of =~
You need spaces around the comparison operator.
This expression is constant. Did you forget a $ somewhere?
[ .. ] can't match globs. Use [[ .. ]] or case statement.
To expand via indirection
Double quote to prevent globbing and word splitting.
Quote 'VS\_CMDS' to make here document expansions happen on the server side rather than on the client.
Tilde does not expand in quotes. Use $HOME.
Quotes/backslashes will be treated literally. Use an array.
Quotes/backslashes in this variable will not be respected.
Remove surrounding $() to avoid executing output.
Remove backticks to avoid executing output.
Remove exec " if script should continue after this command."
Make sure not to read and write the same file in the same pipeline.
On most OS, shebangs can only specify a single parameter
This assignment is only seen by the forked process.
This expansion will not see the mentioned assignment.
Use $((..)) for arithmetics
Ranges can only match single chars (mentioned due to duplicates).
Use a ( subshell ) to avoid having to cd back.
In functions, use return instead of break
continue is only valid in loops.
function' keyword is non-standard. Delete it.
function' keyword is non-standard. Use 'foo()' instead of 'function foo'.
Use ${var:?}" to ensure this never expands to /usr ."
Useless echo? Instead of 'cmd $(echo foo)'
Use $@" if function's $1 should mean script's $1."
A function references arguments but no argument is passed
To assign a variable, do not use set
Assigning an array to a string! Assign as array
Brace expansions and globs are literal in assignments. Quote it or use an array.
Consider using grep -c instead of grep|wc -l.
Expanding an array without an index only gives the first element.
Consider using { cmd1; cmd2; } >> file instead of individual redirects.
This expands when defined
Word is of the form A"B"C" (B indicated). Did you mean "ABC" or "A\\"B\\"C"?"
Aliases can't use positional parameters. Use a function.
Use egrep -q instead of comparing output with [ -n .. ].
-e doesn't work with globs. Use a for loop.
Argument mixes string and array. Use * or separate argument.
This action ignores everything before the -o. Use \\( \\) to group.
Tips depend on target shell and yours is unknown. Add a shebang.
Can only return 0-255. Other data should be written to stdout.
Possible misspelling: FGREP may not be assigned
xtra is referenced but not assigned.
Declare and assign separately to avoid masking return values.
Injecting filenames is fragile and insecure. Use parameters.
Argument to -z is always false due to literal strings.
Instead of '[ true ]', just use 'true'
Instead of '[ 1 ]', just use '1'
read without -r will mangle backslashes.
This does not export 'atom\_env\_pair'. Remove $/${} for that
Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
This nested loop overrides the index variable of its parent.
Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
This parent loop has its index variable overridden.
local' is only valid in functions.
Not supported in dash
Found trailing ] outside test. Missing [?
Trapping signals by number is not well defined. Prefer signal names.
SIGKILL/SIGSTOP can not be trapped.
When used with -p
Quote this invalid brace expansion since it should be passed literally to eval.
time' is undefined for pipelines. time single stage or bash -c instead.
Variable was used as an array but is now assigned a string.
Use array+=(item") to append items to an array."
Check exit code directly with e.g. 'if mycmd;'
This format string has 1 variables
Quote arguments to unset so they're not glob expanded.
Some finds don't have a default path. Specify '.' explicitly.
tempfile is deprecated. Use mktemp instead.
Ash scripts will be checked as Dash. Add '# shellcheck shell=dash' to silence.
This redirection doesn't have a command. Move to its command (or use 'true' as no-op).
Elements in associative arrays need index
The = here is literal. To assign by index
The arguments to this comparison can never be equal. Make sure your syntax is correct.
This word is constant. Did you forget the $ on a variable?
This pattern will never match the case statement's word. Double check them.
egrep is non-standard and deprecated. Use grep -E instead.
fgrep is non-standard and deprecated. Use grep -F instead.
Arrays don't work as operands in [ ]. Use a loop (or concatenate with * instead of @).
Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).
Globs are ignored in [[ ]] except right of =/!=. Use a loop.
Quote to prevent word splitting/globbing
Prefer mapfile or read -a to split command output (or quote to avoid splitting).
Use var=$(command) to assign output (or quote to assign string).
This is a file redirection. Was it supposed to be a comparison or fd operation?
This is a glob used as a command name. Was it supposed to be in ${..}
getopts specified -v
This case is not specified by getopts.
This flag is used as a command name. Bad line break or missing [ .. ]?
Piping to 'rm', a command that doesn't read stdin. Wrong command or missing xargs?
Redirecting to 'true'
Instead of 'let expr'
Invalid flags are not handled. Add a *) case.
This pattern always overrides a later one.
This pattern never matches because of a previous pattern.
This default assignment may cause DoS due to globbing. Quote it.
This cp has no destination. Check the arguments.
This ln has no destination. Check the arguments
which is a non-standard tool. Use builtin 'command -v' instead.
Quote expansions in this for loop glob to prevent wordsplitting
Can't use sudo with builtins like cd. Did you want sudo sh -c .. instead?
Remove superfluous (..) around condition.
Remove superfluous (..) around test command.
Use { ..; } instead of (..) to avoid subshell overhead.
Use -n instead of ! -z.
Use [ -n .. ] instead of ! [ -z .. ].
Can only exit with status 0-255. Other data should be written to stdout/stderr.
Ensure the shebang uses an absolute path to the interpreter
Quote expansions in case patterns to match literally rather than as a glob
Detect unknown binary operator
Unexpected start of line. If breaking lines, |/||/&& should be at the end of the previous one.
This is a unicode quote. Delete and retype it (or ignore/doublequote for literal).
To run as a command, use $(..) instead of '..'
This function is only defined later. Move the definition up.
Redirecting to/from command name instead of file. Did you want pipes/xargs (or quote to ignore)?
This does not read foo. Remove $/${} for that, or use ${var?} to quiet
This is interpreted as a shell file redirection, not a comparison
This shebang specifies a directory. Ensure the interpreter is a file
Remove indentation before end token
You need a space before and after the =
Instead of [ a && b ], use [ a ] && [ b ]
Need a space before :
Redirection applies to the find command itself.
Invalid number for -eq. Use = to compare as string