facebook pixelCodiga Analysis Shell Rules, category error prone
BACK TO LIST

Shell rules

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.

1001

Error prone
Warning

This \\N will be a regular 'N' in this context.

1003

Error prone
Warning

Want to escape a single quote? echo 'This is how it'\\''s done'.

1004

Error prone
Warning

This backslash+linefeed is literal. Break outside single quotes if you just want to break the line.

1007

Error prone
Error

Remove space after = if trying to assign a value (for empty string

1009

Error prone
Warning

The mentioned syntax error was in this elif clause.

1010

Error prone
Error

Use semicolon or linefeed before 'fi' (or quote to make it literal).

1012

Error prone
Error

\\r is just literal 'r' here. For carriage return

1014

Error prone
Error

Use 'if cmd; then ..' to check exit code

1017

Error prone
Critical

Literal carriage return. Run script through tr -d '\\r' .

1018

Error prone
Critical

This is a unicode non-breaking space. Delete and retype it.

1019

Error prone
Critical

Expected this to be an argument to the unary condition.

Learn more

1020

Error prone
Critical

You need a space before the ]].

1035

Error prone
Critical

You are missing a required space after the !.

1036

Error prone
Critical

(' is invalid here. Did you forget to escape it?

1046

Error prone
Critical

Couldn't find 'fi' for this 'if'.

1047

Error prone
Critical

Expected 'fi' matching previously mentioned 'if'.

1048

Error prone
Critical

Can't have empty else clauses (use 'true' as a no-op).

1049

Error prone
Critical

Did you forget the 'then' for this 'if'?

1050

Error prone
Critical

Expected 'then'.

1054

Error prone
Critical

You need a space after the '{'.

1055

Error prone
Critical

You need at least one command here. Use 'true;' as a no-op.

1056

Error prone
Critical

Expected a '}'. If you have one

1058

Error prone
Critical

Expected 'do'.

1061

Error prone
Critical

Couldn't find 'done' for this 'do'.

1062

Error prone
Critical

Expected 'done' matching previously mentioned 'do'.

1064

Error prone
Critical

Expected a { to open the function definition.

1065

Error prone
Critical

Trying to declare parameters? Don't. Use () and refer to params as $1

1066

Error prone
Critical

Don't use $ on the left side of assignments.

1070

Error prone
Critical

Parsing stopped here. Mismatched keywords or invalid parentheses?

1071

Error prone
Critical

ShellCheck only supports sh/bash/dash/ksh scripts. Sorry!

1072

Error prone
Critical

Expected 'then'. Fix any mentioned problems and try again.

1073

Error prone
Critical

Couldn't parse this escaped char. Fix to allow more checks.

1075

Error prone
Critical

Use 'elif' instead of 'else if' (or put 'if' on new line if nesting).

1078

Error prone
Error

Did you forget to close this double quoted string?

1079

Error prone
Warning

This is actually an end quote

1080

Error prone
Critical

You need \\ before line feeds to break lines in [ ].

1082

Error prone
Critical

This file has a UTF-8 BOM. Remove it with: LC\_CTYPE=C sed '1s/^...//' < yourscript .

1084

Error prone
Critical

Use #! and not !# for shebang

1086

Error prone
Critical

Don't use $ on the iterator name in for loops.

1088

Error prone
Critical

Parsing stopped here. Invalid use of parentheses?

1089

Error prone
Critical

Parsing stopped here. Is this keyword correctly matched up?

1091

Error prone
Warning

Not following: /etc/os-release was not specified as input (see shellcheck -x).

1095

Error prone
Critical

You need a space or linefeed between the function name and body.

1101

Error prone
Critical

Delete trailing spaces after \\ to break line (or use quotes for literal space).

1102

Error prone
Error

Shells disambiguate $(( differently or not at all. For $(command substition)

1104

Error prone
Critical

Use #! and not ! for shebang

1105

Error prone
Error

Shells disambiguate (( differently or not at all. For subshell

1110

Error prone
Error

This is a unicode quote. Delete and retype it (or quote to make literal).

1111

Error prone
Error

This is a unicode quote. Delete and retype it (or ignore/singlequote for literal).

1113

Error prone
Critical

Use #! for the shebang

1115

Error prone
Critical

Remove spaces between # and ! in the shebang.

1116

Error prone
Critical

Missing $ on a $((..)) expression? (or use ( ( for arrays).

1119

Error prone
Critical

Add a linefeed between end token and terminating ')'.

1126

Error prone
Critical

Place shellcheck directives before commands

1127

Error prone
Critical

Was this intended as a comment? Use # in sh.

1128

Error prone
Critical

The shebang must be on the first line. Delete blanks and move comments.

2009

Error prone
Warning

Consider using pgrep instead of grepping ps output.

2010

Error prone
Error

Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.

2011

Error prone
Error

Use 'find .. -print0 | xargs -0 ..' or 'find .. -exec .. +' to allow non-alphanumeric filenames.

2014

Error prone
Warning

This will expand once before find runs

2015

Error prone
Warning

Note that A && B || C is not if-then-else. C may run when A is true.

2017

Error prone
Warning

Increase precision by replacing a/b*c with a*c/b.

2018

Error prone
Warning

Use '[:lower:]' to support accents and foreign alphabets.

2019

Error prone
Warning

Use '[:upper:]' to support accents and foreign alphabets.

2020

Error prone
Warning

tr replaces sets of chars

2021

Error prone
Warning

Don't use [] around classes in tr

2022

Error prone
Warning

Note that unlike globs

2023

Error prone
Warning

The shell may override 'time' as seen in man time(1). Use 'command time ..' for that one.

2024

Error prone
Error

sudo doesn't affect redirects. Use sudo cat file | ..

2026

Error prone
Warning

This word is outside of quotes. Did you intend to 'nest ''single quotes'"' instead'? "

2027

Error prone
Error

The surrounding quotes actually unquote this. Remove or escape them.

2028

Error prone
Warning

echo won't expand escape sequences. Consider printf.

2029

Error prone
Warning

Expansion on the client side

2030

Error prone
Warning

Modification of RSYSLOG\_VERSION is local (to subshell caused by pipeline).

2031

Error prone
Warning

RSYSLOG\_VERSION was modified in a subshell. That change might be lost.

2032

Error prone
Warning

Use own script or sh -c '..' to run this from sudo.

2033

Error prone
Error

Shell functions can't be passed to external commands.

2036

Error prone
Error

If you wanted to assign the output of the pipeline

2049

Error prone
Error

"=~ is for regex, but this looks like a glob. Use = instead."

2050

Error prone
Error

This expression is constant. Did you forget the $ on a variable?

2060

Error prone
Error

Quote parameters to tr to prevent glob expansion.

2062

Error prone
Error

Quote the grep pattern so the shell won't interpret it.

2063

Error prone
Error

Grep uses regex

2066

Error prone
Critical

Since you double quoted this

2067

Error prone
Critical

Missing ';' or + terminating -exec. You can't use |/||/&&

2069

Error prone
Error

To redirect stdout+stderr

2070

Error prone
Critical

-n doesn't work with unquoted arguments. Quote or use [[ ]].

2072

Error prone
Critical

Decimals are not supported. Either use integers only

2076

Error prone
Critical

Don't quote rhs of =~

2077

Error prone
Critical

You need spaces around the comparison operator.

2078

Error prone
Critical

This expression is constant. Did you forget a $ somewhere?

2081

Error prone
Critical

[ .. ] can't match globs. Use [[ .. ]] or case statement.

2082

Error prone
Critical

To expand via indirection

2087

Error prone
Error

Quote 'VS\_CMDS' to make here document expansions happen on the server side rather than on the client.

2088

Error prone
Error

Tilde does not expand in quotes. Use $HOME.

2092

Error prone
Error

Remove backticks to avoid executing output.

2093

Error prone
Error

Remove exec " if script should continue after this command."

2096

Error prone
Critical

On most OS, shebangs can only specify a single parameter

2097

Error prone
Error

This assignment is only seen by the forked process.

2098

Error prone
Error

This expansion will not see the mentioned assignment.

2100

Error prone
Error

Use $((..)) for arithmetics

2102

Error prone
Warning

Ranges can only match single chars (mentioned due to duplicates).

2104

Error prone
Critical

In functions, use return instead of break

2105

Error prone
Critical

continue is only valid in loops.

2113

Error prone
Error

function' keyword is non-standard. Use 'foo()' instead of 'function foo'.

2115

Error prone
Error

Use ${var:?}" to ensure this never expands to /usr ."

2124

Error prone
Error

Assigning an array to a string! Assign as array

2125

Error prone
Error

Brace expansions and globs are literal in assignments. Quote it or use an array.

2126

Error prone
Informational

Consider using grep -c instead of grep|wc -l.

2139

Error prone
Error

This expands when defined

2142

Error prone
Critical

Aliases can't use positional parameters. Use a function.

2143

Error prone
Informational

Use egrep -q instead of comparing output with [ -n .. ].

2144

Error prone
Critical

-e doesn't work with globs. Use a for loop.

2146

Error prone
Error

This action ignores everything before the -o. Use \\( \\) to group.

2152

Error prone
Critical

Can only return 0-255. Other data should be written to stdout.

2156

Error prone
Error

Injecting filenames is fragile and insecure. Use parameters.

2157

Error prone
Critical

Argument to -z is always false due to literal strings.

2160

Error prone
Informational

Instead of '[ true ]', just use 'true'

2161

Error prone
Informational

Instead of '[ 1 ]', just use '1'

2165

Error prone
Error

This nested loop overrides the index variable of its parent.

2166

Error prone
Warning

Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.

2167

Error prone
Error

This parent loop has its index variable overridden.

2168

Error prone
Critical

local' is only valid in functions.

2169

Error prone
Error

Not supported in dash

2171

Error prone
Error

Found trailing ] outside test. Missing [?

2172

Error prone
Error

Trapping signals by number is not well defined. Prefer signal names.

2173

Error prone
Critical

SIGKILL/SIGSTOP can not be trapped.

2174

Error prone
Error

When used with -p

2175

Error prone
Informational

Quote this invalid brace expansion since it should be passed literally to eval.

2176

Error prone
Error

time' is undefined for pipelines. time single stage or bash -c instead.

2178

Error prone
Error

Variable was used as an array but is now assigned a string.

2179

Error prone
Error

Use array+=(item") to append items to an array."

2183

Error prone
Error

This format string has 1 variables

2184

Error prone
Error

Quote arguments to unset so they're not glob expanded.

2187

Error prone
Error

Ash scripts will be checked as Dash. Add '# shellcheck shell=dash' to silence.

2188

Error prone
Error

This redirection doesn't have a command. Move to its command (or use 'true' as no-op).

2190

Error prone
Error

Elements in associative arrays need index

2193

Error prone
Error

The arguments to this comparison can never be equal. Make sure your syntax is correct.

2194

Error prone
Error

This word is constant. Did you forget the $ on a variable?

2195

Error prone
Error

This pattern will never match the case statement's word. Double check them.

2197

Error prone
Warning

fgrep is non-standard and deprecated. Use grep -F instead.

2199

Error prone
Critical

Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

2203

Error prone
Critical

Globs are ignored in [[ ]] except right of =/!=. Use a loop.

2210

Error prone
Error

This is a file redirection. Was it supposed to be a comparison or fd operation?

2211

Error prone
Error

This is a glob used as a command name. Was it supposed to be in ${..}

2213

Error prone
Error

getopts specified -v

2214

Error prone
Error

This case is not specified by getopts.

2215

Error prone
Error

This flag is used as a command name. Bad line break or missing [ .. ]?

2216

Error prone
Error

Piping to 'rm', a command that doesn't read stdin. Wrong command or missing xargs?

2217

Error prone
Error

Redirecting to 'true'

2220

Error prone
Error

Invalid flags are not handled. Add a *) case.

2221

Error prone
Error

This pattern always overrides a later one.

2222

Error prone
Error

This pattern never matches because of a previous pattern.

2225

Error prone
Critical

This cp has no destination. Check the arguments.

2226

Error prone
Error

This ln has no destination. Check the arguments

2232

Error prone
Error

Can't use sudo with builtins like cd. Did you want sudo sh -c .. instead?

2233

Error prone
Informational

Remove superfluous (..) around condition.

2234

Error prone
Informational

Remove superfluous (..) around test command.

2235

Error prone
Informational

Use { ..; } instead of (..) to avoid subshell overhead.

2236

Error prone
Informational

Use -n instead of ! -z.

2237

Error prone
Informational

Use [ -n .. ] instead of ! [ -z .. ].

2242

Error prone
Critical

Can only exit with status 0-255. Other data should be written to stdout/stderr.

2057

Error prone
Error

Detect unknown binary operator

1112

Error prone
Warning

This is a unicode quote. Delete and retype it (or ignore/doublequote for literal).

2218

Error prone
Warning

This function is only defined later. Move the definition up.

2229

Error prone
Warning

This does not read foo. Remove $/${} for that, or use ${var?} to quiet

2065

Error prone
Warning

This is interpreted as a shell file redirection, not a comparison

2246

Error prone
Critical

This shebang specifies a directory. Ensure the interpreter is a file

2227

Error prone
Warning

Redirection applies to the find command itself.

2170

Error prone
Warning

Invalid number for -eq. Use = to compare as string