Replaced "Contraindications" with "Exceptions".

Vidar Holen
2015-01-21 14:31:24 -08:00
parent 28b10537ac
commit 36c3eec327
85 changed files with 85 additions and 85 deletions

@@ -24,6 +24,6 @@ If the backslash was supposed to be literal, single quote it.
If the purpose is to run an external command rather than an alias, prefer `command`. If the purpose is to run an external command rather than an alias, prefer `command`.
### Contraindications ### Exceptions
If you have an alias and a function (as opposed to an external command), you can either ignore this message or use `"name"` instead of `\name` to quiet ShellCheck. If you have an alias and a function (as opposed to an external command), you can either ignore this message or use `"name"` instead of `\name` to quiet ShellCheck.

@@ -24,5 +24,5 @@ Instead, it runs `nl` (the "number lines" command) and sets `LANGUAGE` to an emp
Since trying to assign values this way is a common mistake, ShellCheck warns about it and asks you to be explicit when assigning empty strings (except for `IFS`, due to the common `IFS= read ..` idiom). Since trying to assign values this way is a common mistake, ShellCheck warns about it and asks you to be explicit when assigning empty strings (except for `IFS`, due to the common `IFS= read ..` idiom).
### Contraindications ### Exceptions
If you're familiar with this behavior and feel that the explicit version is unnecessary, you can ignore the message. ``alias shellcheck=`shellcheck -e SC1007` `` If you're familiar with this behavior and feel that the explicit version is unnecessary, you can ignore the message. ``alias shellcheck=`shellcheck -e SC1007` ``

@@ -14,6 +14,6 @@ Blog software and word processors frequently replaces ASCII quotes `""` with fan
Simply delete them and retype them in your editor. Simply delete them and retype them in your editor.
### Contraindications ### Exceptions
If you really want literal Unicode double quotes, you can put them in single quotes (or unicode single quotes in double quotes) to make shellcheck ignore them. If you really want literal Unicode double quotes, you can put them in single quotes (or unicode single quotes in double quotes) to make shellcheck ignore them.

@@ -12,6 +12,6 @@
Some software, like OS X, Word and Wordpress, may automatically replace your regular quotes with slanted unicode quotes. Try deleting and retyping them, and/or disable "smart quotes" in your editor or OS. Some software, like OS X, Word and Wordpress, may automatically replace your regular quotes with slanted unicode quotes. Try deleting and retyping them, and/or disable "smart quotes" in your editor or OS.
### Contraindications ### Exceptions
None None

@@ -12,6 +12,6 @@
Bourne shells are very whitespace sensitive. Adding or removing spaces can drastically alter the meaning of a script. In these cases, ShellCheck has noticed that you're missing a space at the position indicated. Bourne shells are very whitespace sensitive. Adding or removing spaces can drastically alter the meaning of a script. In these cases, ShellCheck has noticed that you're missing a space at the position indicated.
### Contraindications ### Exceptions
None. None.

@@ -16,6 +16,6 @@ For legacy reasons, `$10` is interpreted as the variable `$1` followed by the li
Curly braces are needed to tell the shell that both digits are part of the parameter expansion. Curly braces are needed to tell the shell that both digits are part of the parameter expansion.
### Contraindications ### Exceptions
If you wanted the trailing digits to be literal, `${1}0` will make this clear to both humans and shellcheck. If you wanted the trailing digits to be literal, `${1}0` will make this clear to both humans and shellcheck.

@@ -28,6 +28,6 @@ Or simply don't indent the end token:
Your editor may be automatically replacing tabs with spaces, either when you type them or when you save the file or both. If you're unable to make it stop, just don't indent the end token. Your editor may be automatically replacing tabs with spaces, either when you type them or when you save the file or both. If you're unable to make it stop, just don't indent the end token.
### Contraindications ### Exceptions
None. But note that copy-pasting code to [shellcheck.net](http://www.shellcheck.net) may also turn correct tabs into spaces on some OS. None. But note that copy-pasting code to [shellcheck.net](http://www.shellcheck.net) may also turn correct tabs into spaces on some OS.

@@ -14,6 +14,6 @@ Both `&` and `;` terminate the command. You should only use one of them.
### Contraindications ### Exceptions
None. None.

@@ -18,6 +18,6 @@ Alternatively, if the goal was to assign to a variable whose name is in another
Unlike Perl or PHP, `$` is not used when assigning to a variable. Unlike Perl or PHP, `$` is not used when assigning to a variable.
### Contraindications ### Exceptions
None None

@@ -12,6 +12,6 @@
Shells are space sensitive. `foo=42` means to assign `42` to the variable `foo`. `foo = 42` means to run a command named `foo`, and pass `=` as `$1` and `42` as `$2`. Shells are space sensitive. `foo=42` means to assign `42` to the variable `foo`. `foo = 42` means to run a command named `foo`, and pass `=` as `$1` and `42` as `$2`.
### Contraindications ### Exceptions
If you actually wanted to run a command named foo and provide `=` as the first argument, simply quote it to make ShellCheck be quiet: `foo "=" 42`. If you actually wanted to run a command named foo and provide `=` as the first argument, simply quote it to make ShellCheck be quiet: `foo "=" 42`.

@@ -16,7 +16,7 @@ In some fonts it's hard to tell ticks apart, but Bash strongly distinguishes bet
Backticks start command expansions, while forward ticks are literal. To help spot bugs, ShellCheck parses backticks and forward ticks interchangeably. Backticks start command expansions, while forward ticks are literal. To help spot bugs, ShellCheck parses backticks and forward ticks interchangeably.
### Contraindications ### Exceptions
If you want to write out literal forward ticks, such as fancyful ascii quotation marks: If you want to write out literal forward ticks, such as fancyful ascii quotation marks:

@@ -16,7 +16,7 @@ The first line is missing a quote.
ShellCheck warns when it detects multi-line double quoted, single quoted or backticked strings when the character that follows it looks out of place. ShellCheck warns when it detects multi-line double quoted, single quoted or backticked strings when the character that follows it looks out of place.
### Contraindications ### Exceptions
If you do want a multiline variable, just make sure the character after it is a quote, space or line feed. If you do want a multiline variable, just make sure the character after it is a quote, space or line feed.

@@ -18,6 +18,6 @@
Shells are case sensitive and do not accept `If` or `IF` in place of lowercase `if`. Shells are case sensitive and do not accept `If` or `IF` in place of lowercase `if`.
### Contraindications ### Exceptions
If you're aware of this and insist on naming a function `WHILE`, you can quote the name to prevent shellcheck from thinking you meant `while`. If you're aware of this and insist on naming a function `WHILE`, you can quote the name to prevent shellcheck from thinking you meant `while`.

@@ -27,6 +27,6 @@ In the example eval, the code works fine. However, we can quiet the warning and
ShellCheck does not warn about `{}`, since this is frequently used with `find` and rarely indicates a bug. ShellCheck does not warn about `{}`, since this is frequently used with `find` and rarely indicates a bug.
### Contraindications ### Exceptions
This error is harmless when the curly brackets are supposed to be literal, in e.g. `awk {'print $1'}`. However, it's cleaner and less error prone to simply include them inside the quotes: `awk '{print $1}'`. This error is harmless when the curly brackets are supposed to be literal, in e.g. `awk {'print $1'}`. However, it's cleaner and less error prone to simply include them inside the quotes: `awk '{print $1}'`.

@@ -14,6 +14,6 @@
The shebang has been accidentally swapped. The `#` should come first: `#!`, not `!#`. The shebang has been accidentally swapped. The `#` should come first: `#!`, not `!#`.
### Contraindications ### Exceptions
None. None.

@@ -20,6 +20,6 @@ The variable is named `var`, and can be expanded to its value with `$var`.
The `for` loop expects the variable's name, not its value (and the name can not be specified indirectly). The `for` loop expects the variable's name, not its value (and the name can not be specified indirectly).
### Contraindications ### Exceptions
None. None.

@@ -14,6 +14,6 @@ For compatibility reasons, `$foo[bar]` is interpreted as the variable `$foo` fol
Curly braces are needed to tell the shell that the square brackets are part of the expansion. Curly braces are needed to tell the shell that the square brackets are part of the expansion.
### Contraindications ### Exceptions
If you want the square brackets to be treated literally or as a glob, you can use `${var}[idx]` to prevent this warning. If you want the square brackets to be treated literally or as a glob, you can use `${var}[idx]` to prevent this warning.

@@ -12,7 +12,7 @@
Let's assume somewhere earlier in your code you have put data into a variable (Ex: $string). Now you want to do a search and replace inside the contents of $string and echo the contents out. You could pass this to sed as done in the example above, but for simple substitutions utilizing the shell for the same feature is a lot simpler and should be utilized whenever possible. Let's assume somewhere earlier in your code you have put data into a variable (Ex: $string). Now you want to do a search and replace inside the contents of $string and echo the contents out. You could pass this to sed as done in the example above, but for simple substitutions utilizing the shell for the same feature is a lot simpler and should be utilized whenever possible.
### Contraindications ### Exceptions
Occasionally a more complex sed substitution is required. For example, getting the last character of a string. Occasionally a more complex sed substitution is required. For example, getting the last character of a string.

@@ -16,6 +16,6 @@ It's more efficient and less roundabout to simply use redirection. This is espec
Many tools also accept optional filenames, e.g. `grep -q foo file` instead of `cat file | grep -q foo`. Many tools also accept optional filenames, e.g. `grep -q foo file` instead of `cat file | grep -q foo`.
### Contraindications ### Exceptions
None. None.

@@ -16,7 +16,7 @@
> The expr utility has a rather difficult syntax [...] In many cases, the arithmetic and string features provided as part of the shell command language are easier to use than their equivalents in expr. Newly written scripts should avoid expr in favor of the new features within the shell. > The expr utility has a rather difficult syntax [...] In many cases, the arithmetic and string features provided as part of the shell command language are easier to use than their equivalents in expr. Newly written scripts should avoid expr in favor of the new features within the shell.
### Contraindications ### Exceptions
`sh` doesn't have a great replacement for the `:` operator (regex match). ShellCheck tries not to warn when using expr with `:`, but e.g. `op=:; expr string "$op" regex` still trigger it. `sh` doesn't have a great replacement for the `:` operator (regex match). ShellCheck tries not to warn when using expr with `:`, but e.g. `op=:; expr string "$op" regex` still trigger it.

@@ -18,6 +18,6 @@ Backtick command substitution `` `..` `` is legacy syntax with several problems.
`$(..)` command substitution has none of these problems, and is therefore strongly encouraged. `$(..)` command substitution has none of these problems, and is therefore strongly encouraged.
### Contraindications ### Exceptions
None. None.

@@ -12,7 +12,7 @@
If you are just after a pid from a running program, then pgrep is a much safer alternative. Especially if you are also looking for a pid belonging to a certain user or group. All of the parameters are in one command and it cat eliminate multiple greps, cuts, seds, awks, ect. If you are just after a pid from a running program, then pgrep is a much safer alternative. Especially if you are also looking for a pid belonging to a certain user or group. All of the parameters are in one command and it cat eliminate multiple greps, cuts, seds, awks, ect.
### Contraindications ### Exceptions
What if you have the pid and you are looking for the matching program name? What if you have the pid and you are looking for the matching program name?

@@ -43,7 +43,7 @@ The while loop will print:
Line: bar Line: bar
### Contraindications ### Exceptions
If you want to read word by word, you should still use a while read loop (e.g. with `read -a` to read words into an array). If you want to read word by word, you should still use a while read loop (e.g. with `read -a` to read words into an array).

@@ -25,5 +25,5 @@ For the code sample above, if the script was run with stdout closed for any reas
If an `if` clause is used instead, this problem is avoided. If an `if` clause is used instead, this problem is avoided.
### Contraindications ### Exceptions
Ignore this warning when you actually do intend to run C when either A or B fails. Ignore this warning when you actually do intend to run C when either A or B fails.

@@ -16,7 +16,7 @@ Single quotes prevent expansion of everything, including variables and command s
If you want to use the values of variables and such, use double quotes instead. If you want to use the values of variables and such, use double quotes instead.
### Contraindications ### Exceptions
If you want `$stuff` to be a literal dollar sign followed by the characters "stuff", you can ignore this message. If you want `$stuff` to be a literal dollar sign followed by the characters "stuff", you can ignore this message.

@@ -16,6 +16,6 @@ In this case, it transliterates h->g, e->o, l->d, o->y, resulting in the string
The solution is to use a tool that does string search and replace, such as sed. The solution is to use a tool that does string search and replace, such as sed.
### Contraindications ### Exceptions
None. None.

@@ -17,6 +17,6 @@ As a regular expression, "foo*" means "f followed by 1 or more o's, anywhere", e
This construct is way more common as a glob than as a regex, so ShellCheck notifies you about it. This construct is way more common as a glob than as a regex, so ShellCheck notifies you about it.
### Contraindications ### Exceptions
If you're aware of the above, you can ignore this message. If you'd like shellcheck to be quiet, use a [[directive]] or `'fo[o]*'`. If you're aware of the above, you can ignore this message. If you'd like shellcheck to be quiet, use a [[directive]] or `'fo[o]*'`.

@@ -27,6 +27,6 @@ Appending:
echo 'data' | sudo sh -c 'cat >> file' echo 'data' | sudo sh -c 'cat >> file'
### Contraindications ### Exceptions
If you want to run a command as root but redirect as the normal user, you can ignore this message. If you want to run a command as root but redirect as the normal user, you can ignore this message.

@@ -14,6 +14,6 @@ Bash is unable to determine exactly which parts of your prompt are text and whic
Note: ShellCheck offers this as a helpful hint and not a robust check. Don't rely on ShellCheck to verify that your prompt is correct. Note: ShellCheck offers this as a helpful hint and not a robust check. Don't rely on ShellCheck to verify that your prompt is correct.
### Contraindications ### Exceptions
None. None.

@@ -19,6 +19,6 @@ Note that in many cases, this number is only used to see whether there are match
echo "The file contains the pattern" echo "The file contains the pattern"
fi fi
### Contraindications ### Exceptions
If you e.g. want to count characters instead of lines, and you actually care about the number and not just whether it's greater than 0. If you e.g. want to count characters instead of lines, and you actually care about the number and not just whether it's greater than 0.

@@ -20,6 +20,6 @@ In this case, ShellCheck has noticed that the quotes around the expansion are un
If the quotes were supposed to be literal, they should be escaped. If the quotes were supposed to quote an expansion (as in the example), they should be removed because this is already a double quoted string. If the quotes were supposed to be literal, they should be escaped. If the quotes were supposed to quote an expansion (as in the example), they should be removed because this is already a double quoted string.
### Contraindications ### Exceptions
None. None.

@@ -20,6 +20,6 @@ If you actually wanted a literal backslash-t, use
echo "\\t" echo "\\t"
### Contraindications ### Exceptions
None None

@@ -22,7 +22,7 @@ and will print out the client's hostname, not the server's hostname.
By escaping the `$` in `$HOSTNAME`, it will be transmitted literally and evaluated on the server instead. By escaping the `$` in `$HOSTNAME`, it will be transmitted literally and evaluated on the server instead.
### Contraindications ### Exceptions
If you do want your string expanded on the client side, you can safely ignore this message. If you do want your string expanded on the client side, you can safely ignore this message.

@@ -55,6 +55,6 @@ Anything executed by external processes:
This applies not only to setting variables, but also setting shell options and changing directories. This applies not only to setting variables, but also setting shell options and changing directories.
### Contraindications ### Exceptions
You can ignore this error if you don't care that the changes aren't reflected, because work on the value branches and shouldn't be recombined. You can ignore this error if you don't care that the changes aren't reflected, because work on the value branches and shouldn't be recombined.

@@ -15,7 +15,7 @@ Shell functions are only known to the shell. External commands like `find`, `xar
Instead, the function contents can be executed in a shell, either through `sh -c` or by creating a separate shell script as an executable file. Instead, the function contents can be executed in a shell, either through `sh -c` or by creating a separate shell script as an executable file.
### Contraindications ### Exceptions
If you're intentionally passing a word that happens to have the same name as a declared function, you can quote it to make shellcheck ignore it, e.g. If you're intentionally passing a word that happens to have the same name as a declared function, you can quote it to make shellcheck ignore it, e.g.

@@ -14,7 +14,7 @@
Variables not used for anything are often associated with bugs, so ShellCheck warns about them. Variables not used for anything are often associated with bugs, so ShellCheck warns about them.
### Contraindications ### Exceptions
ShellCheck may not always realize that the variable is in use (especially with indirection), and may not realize you don't care (with throwaway variables or unimplemented features). ShellCheck may not always realize that the variable is in use (especially with indirection), and may not realize you don't care (with throwaway variables or unimplemented features).

@@ -12,6 +12,6 @@
By default, `xargs` interprets spaces and quotes in an unsafe and unexpected way. Whenever it's used, it should be used with `-0` or `--null` to split on `\0` bytes, and `find` should be made to output `\0` separated filenames. By default, `xargs` interprets spaces and quotes in an unsafe and unexpected way. Whenever it's used, it should be used with `-0` or `--null` to split on `\0` bytes, and `find` should be made to output `\0` separated filenames.
### Contraindications ### Exceptions
None. None.

@@ -35,6 +35,6 @@ ShellCheck has detected that your for loop iterates over a single, constant valu
You should make sure that whatever you loop over will expand into multiple words. You should make sure that whatever you loop over will expand into multiple words.
### Contraindications ### Exceptions
None. None.

@@ -20,6 +20,6 @@ Let's say you have three arguments: `baz`, `foo bar` and `*`
Since the latter is rarely expected or desired, ShellCheck warns about it. Since the latter is rarely expected or desired, ShellCheck warns about it.
### Contraindications ### Exceptions
None. None.

@@ -32,6 +32,6 @@ or more carefully (if `from`/`to` could be user input, or if the brace expansion
done < <(eval "printf '%s\0' $(printf "{%q..%q}.jpg" "$from" "$to")") done < <(eval "printf '%s\0' $(printf "{%q..%q}.jpg" "$from" "$to")")
### Contraindications ### Exceptions
None (if you're writing for e.g. zsh, make sure the shebang indicates this so shellcheck won't warn) None (if you're writing for e.g. zsh, make sure the shebang indicates this so shellcheck won't warn)

@@ -32,6 +32,6 @@ This is not a bash issue, but a simple, common logical mistake applicable to all
This statement is identical to `! [[ $1 = foo || $1 = bar ]]`, which also works correctly. This statement is identical to `! [[ $1 = foo || $1 = bar ]]`, which also works correctly.
### Contraindications ### Exceptions
None. None.

@@ -20,7 +20,7 @@ The first printf writes `Unit test coverage: 96%`.
The second writes ``bash: printf: `\': invalid format character`` The second writes ``bash: printf: `\': invalid format character``
### Contraindications ### Exceptions
Sometimes you may actually want to interpret data as a format string, like in: Sometimes you may actually want to interpret data as a format string, like in:

@@ -12,6 +12,6 @@
`[:digit:]` is a shell glob that matches any single character file named e.g. `g` or `t` in the current directory. Quoting it prevents the script from breaking in directories with files like this. `[:digit:]` is a shell glob that matches any single character file named e.g. `g` or `t` in the current directory. Quoting it prevents the script from breaking in directories with files like this.
### Contraindications ### Exceptions
None None

@@ -21,6 +21,6 @@ If the intention was to match "any number of characters followed by foo", use `'
This also means that `f*` will match "hello", because `f*` matches 0 (or more) "f"s and there are indeed 0 "f" characters in "hello". Again, use `grep 'f'` to find strings containing "f", or `grep '^f'` to find strings starting with "f". This also means that `f*` will match "hello", because `f*` matches 0 (or more) "f"s and there are indeed 0 "f" characters in "hello". Again, use `grep 'f'` to find strings containing "f", or `grep '^f'` to find strings starting with "f".
### Contraindications ### Exceptions
If you're aware of the differences between globs and regex, you can ignore this message. If you're aware of the differences between globs and regex, you can ignore this message.

@@ -16,6 +16,6 @@ In the example, the message will contain the date on which the trap was declared
Using single quotes will prevent expansion at declaration time, and save it for execution time. Using single quotes will prevent expansion at declaration time, and save it for execution time.
### Contraindications ### Exceptions
If you don't care that the trap code is expanded early because the commands/variables won't change during execution of the script, or because you want to use the current and not the future values, then you can ignore this message. If you don't care that the trap code is expanded early because the commands/variables won't change during execution of the script, or because you want to use the current and not the future values, then you can ignore this message.

@@ -31,6 +31,6 @@ The correct code depends on your intention. Let's say you're in a directory with
You get this warning because you have a loop that will only ever run exactly one iteration. Since you have a loop, you clearly expect it to run more than once. You just have to decide how it should be split up. You get this warning because you have a loop that will only ever run exactly one iteration. Since you have a loop, you clearly expect it to run more than once. You just have to decide how it should be split up.
### Contraindications ### Exceptions
None. None.

@@ -26,6 +26,6 @@ You can also use find `-a` instead of shell `&&`:
This will have the same effect (`-a` is also the default when two commands are specified, and can therefore be omitted). This will have the same effect (`-a` is also the default when two commands are specified, and can therefore be omitted).
### Contraindications ### Exceptions
None None

@@ -20,6 +20,6 @@ Let's say you have three arguments: `baz`, `foo bar` and `*`
Since the latter is rarely expected or desired, ShellCheck warns about it. Since the latter is rarely expected or desired, ShellCheck warns about it.
### Contraindications ### Exceptions
None. None.

@@ -18,6 +18,6 @@ The correct code means "Point stdout to /dev/null. Then point stderr to where st
In other words, the problematic code hides stdout and shows stderr. The correct code hides both stderr and stdout, which is usually the intention. In other words, the problematic code hides stdout and shows stderr. The correct code hides both stderr and stdout, which is usually the intention.
### Contraindications ### Exceptions
If you want stderr as stdout and stdout to a file, you can ignore this message. If you want stderr as stdout and stdout to a file, you can ignore this message.

@@ -13,6 +13,6 @@
Bash and Posix sh does not support decimals in numbers. Decimals should either be avoided, or compared using a tool that does support them. Bash and Posix sh does not support decimals in numbers. Decimals should either be avoided, or compared using a tool that does support them.
### Contraindications ### Exceptions
If the strings happen to be version numbers and you're using `<`, or `>` to compare them as strings, and you consider this an acceptable thing to do, then you can ignore this warning. If the strings happen to be version numbers and you're using `<`, or `>` to compare them as strings, and you consider this an acceptable thing to do, then you can ignore this warning.

@@ -16,6 +16,6 @@
Always use spaces around the comparison operator in `[..]` and `[[..]]`, otherwise it won't be recognized as an operator. Always use spaces around the comparison operator in `[..]` and `[[..]]`, otherwise it won't be recognized as an operator.
### Contraindications ### Exceptions
None. None.

@@ -27,6 +27,6 @@ These strings do not, leaving a literal tilde:
~"/file" # Wrong: slash is quoted when it shouldn't be. ~"/file" # Wrong: slash is quoted when it shouldn't be.
~user"/hello world.txt" # Wrong: slash is quoted when it shouldn't be. ~user"/hello world.txt" # Wrong: slash is quoted when it shouldn't be.
### Contraindications ### Exceptions
If you don't want the tilde to be expanded, you can ignore this message. If you don't want the tilde to be expanded, you can ignore this message.

@@ -39,6 +39,6 @@ If you ever accidentally forget to use proper quotes, such as with:
Then you can use `touch "'; rm -rf \$'\x2F'; '.txt"` (or someone can trick you into downloading a file with this name, or create a zip file or git repo containing it, or changing their nick and have your chat client create the file for a chat log, or...), and running the script to list your files will run the command `rm -rf /`. Then you can use `touch "'; rm -rf \$'\x2F'; '.txt"` (or someone can trick you into downloading a file with this name, or create a zip file or git repo containing it, or changing their nick and have your chat client create the file for a chat log, or...), and running the script to list your files will run the command `rm -rf /`.
### Contraindications ### Exceptions
Few and far between. Few and far between.

@@ -16,7 +16,7 @@ In this case, `grep foo file.txt` will immediately try to read `file.txt` while
This is a race condition, and results in the file being partially or (far more likely) entirely truncated. This is a race condition, and results in the file being partially or (far more likely) entirely truncated.
### Contraindications ### Exceptions
You can ignore this error if: You can ignore this error if:

@@ -15,6 +15,6 @@ Most operating systems, including Linux, FreeBSD and OS X, allow only a single p
The shebang should be rewritten to use at most one parameter. Shell options can instead be set in the body of the script. The shebang should be rewritten to use at most one parameter. Shell options can instead be set in the body of the script.
### Contraindications ### Exceptions
None. None.

@@ -24,6 +24,6 @@ However, `"$name"` is not expanded by `cmd`. `"$name"` is expanded by the shell
The solution is to set the variable and export the variable first. If limited scope is desired, a `( subshell )` can be used. The solution is to set the variable and export the variable first. If limited scope is desired, a `( subshell )` can be used.
### Contraindications ### Exceptions
In the strange and fabricated scenarios where the script and a program uses a variable name for two different purposes, you can ignore this message. This is hard to conceive, since scripts should use lowercase variable names specifically to avoid collisions with the environment. In the strange and fabricated scenarios where the script and a program uses a variable name for two different purposes, you can ignore this message. This is hard to conceive, since scripts should use lowercase variable names specifically to avoid collisions with the environment.

@@ -12,6 +12,6 @@
Predefined character groups are supposed to be used inside character ranges. `[:digit:]` matches one of "digt:" just like `[abc]` matches one of "abc". `[[:digit:]]` matches a digit. Predefined character groups are supposed to be used inside character ranges. `[:digit:]` matches one of "digt:" just like `[abc]` matches one of "abc". `[[:digit:]]` matches a digit.
### Contraindications ### Exceptions
When passing an argument to `tr` which parses these by itself without relying on globbing, you should quote it instead, e.g. `tr -d '[:digit:]'` When passing an argument to `tr` which parses these by itself without relying on globbing, you should quote it instead, e.g. `tr -d '[:digit:]'`

@@ -37,6 +37,6 @@ In this case, `somestuff` will run in the wrong directory and `cd ..` will take
Check `cd`s exit status and/or use subshells to limit the effects of `cd`. Check `cd`s exit status and/or use subshells to limit the effects of `cd`.
### Contraindications ### Exceptions
None known. None known.

@@ -12,6 +12,6 @@
Most of the time, this is an useless echo meaning it isn't doing anything that the Shell can't already do. Having the shell expand the contents for you is simpler and more reliable. Just remember to double quote the argument! Most of the time, this is an useless echo meaning it isn't doing anything that the Shell can't already do. Having the shell expand the contents for you is simpler and more reliable. Just remember to double quote the argument!
### Contraindications ### Exceptions
None I am aware of at the moment. None I am aware of at the moment.

@@ -20,6 +20,6 @@ It's commonly believed that `su` makes a session run as another user. In reality
To run commands as another user, use `sudo some command` or `su -c 'some command'`. `sudo` is preferred when available, as it doesn't require additional quoting and can be configured to run passwordless if desired. To run commands as another user, use `sudo some command` or `su -c 'some command'`. `sudo` is preferred when available, as it doesn't require additional quoting and can be configured to run passwordless if desired.
### Contraindications ### Exceptions
If you're aware of the above and want to e.g. start an interactive shell for a user, feel free to ignore this message. If you're aware of the above and want to e.g. start an interactive shell for a user, feel free to ignore this message.

@@ -30,6 +30,6 @@ Note that `"$@"` refers to the current context's positional parameters, so if yo
second() { echo "The first script parameter is: $1"; } second() { echo "The first script parameter is: $1"; }
first "$@" first "$@"
### Contraindications ### Exceptions
If the parameters are optional and you currently just don't want to use them, you can ignore this message. If the parameters are optional and you currently just don't want to use them, you can ignore this message.

@@ -15,6 +15,6 @@
To assign variables, use `var=value` with no `set` or other qualifiers. To assign variables, use `var=value` with no `set` or other qualifiers.
### Contraindications ### Exceptions
If you actually do want to set positional parameters, simply quoting them or using `--` will make shellcheck stop warning, e.g. `set -- var1 var2` or `set "foo=bar"`. If you actually do want to set positional parameters, simply quoting them or using `--` will make shellcheck stop warning, e.g. `set -- var1 var2` or `set "foo=bar"`.

@@ -12,6 +12,6 @@
The operators `<=` and `>=` are not supported by Bourne shells. Instead of "less than or equal", rewrite as "not greater than". The operators `<=` and `>=` are not supported by Bourne shells. Instead of "less than or equal", rewrite as "not greater than".
### Contraindications ### Exceptions
None None

@@ -25,6 +25,6 @@ You get this warning when ShellCheck suspects that you didn't meant to overwrite
Best shell scripting practice is to always use lowercase variable names to avoid accidentally overwriting exported and internal variables. Best shell scripting practice is to always use lowercase variable names to avoid accidentally overwriting exported and internal variables.
### Contraindications ### Exceptions
If you're aware of the above and really do want to set your shell search path to `/my/dir`, you can ignore this warning. If you're aware of the above and really do want to set your shell search path to `/my/dir`, you can ignore this warning.

@@ -32,6 +32,6 @@ If you want to assign N elements as N elements, use an array, e.g. `myArray=( "$
If you want to assign N elements as 1 element by concatenating them, use `*` instead of `@`, e.g. `myVar=${myArray[*]}` (this separates elements with the first character of `IFS`, usually space). If you want to assign N elements as 1 element by concatenating them, use `*` instead of `@`, e.g. `myVar=${myArray[*]}` (this separates elements with the first character of `IFS`, usually space).
### Contraindications ### Exceptions
None. None.

@@ -18,6 +18,6 @@ To make the variable contain all png files or 1 through 9, use an array as demon
If you intended to assign these values as literals, quote them (e.g. `var="*.png"`). If you intended to assign these values as literals, quote them (e.g. `var="*.png"`).
### Contraindications ### Exceptions
None. None.

@@ -24,6 +24,6 @@ To get all elements as separate parameters, use the index `@` (and make sure to
To get all elements as a single parameter, concatenated by the first character in `IFS`, use the index `*`. In the example, `echo "${myarray[*]}"` is equivalent to `echo "foo bar"`. To get all elements as a single parameter, concatenated by the first character in `IFS`, use the index `*`. In the example, `echo "${myarray[*]}"` is equivalent to `echo "foo bar"`.
### Contraindications ### Exceptions
None. None.

@@ -19,6 +19,6 @@
Rather than adding `>> something` after every single line, you can simply group the relevant commands and redirect the group. Rather than adding `>> something` after every single line, you can simply group the relevant commands and redirect the group.
### Contraindications ### Exceptions
This is mainly a stylistic issue, and can freely be ignored. This is mainly a stylistic issue, and can freely be ignored.

@@ -14,6 +14,6 @@ Shells have two sets of comparison operators: for integers (`-eq`, `-gt`, ...) a
If you are in fact comparing integers, double check your parameters. Certain mistakes like `$$foo` or `${bar}}` can introduce non-numeric characters into otherwise numeric arguments. If you are in fact comparing integers, double check your parameters. Certain mistakes like `$$foo` or `${bar}}` can introduce non-numeric characters into otherwise numeric arguments.
### Contraindications ### Exceptions
None. None.

@@ -14,6 +14,6 @@ With double quotes, this particular alias will be defined as `echo /home/me`, so
By using single quotes or escaping any expansions, we define the alias as `echo $PWD`, which will be expanded when we use the alias. This is the far more common use case. By using single quotes or escaping any expansions, we define the alias as `echo $PWD`, which will be expanded when we use the alias. This is the far more common use case.
### Contraindications ### Exceptions
If you don't mind that your alias definition is expanded at define time, you can ignore this warning. If you don't mind that your alias definition is expanded at define time, you can ignore this warning.

@@ -19,6 +19,6 @@ It's common not to realize that double quotes can span multiple elements. For ex
When ShellCheck detects the former style (i.e. the double quotes include only a single element each), it will suppress the warning. When ShellCheck detects the former style (i.e. the double quotes include only a single element each), it will suppress the warning.
### Contraindications ### Exceptions
If you know that the quotes are ineffectual but you prefer it stylistically, you can ignore this message. If you know that the quotes are ineffectual but you prefer it stylistically, you can ignore this message.

@@ -12,6 +12,6 @@
`IFS="\t"` splits on backslash and the letter "t". `IFS=$'\t'` splits on tab. `IFS="\t"` splits on backslash and the letter "t". `IFS=$'\t'` splits on tab.
### Contraindications ### Exceptions
It's extremely rare to want to split on the letter "n" or "t", rather than linefeed or tab. It's extremely rare to want to split on the letter "n" or "t", rather than linefeed or tab.

@@ -13,6 +13,6 @@
Aliases just substitute the start of a command with something else. They therefore can't use positional parameters, such as `$1`. Rewrite your alias as a function. Aliases just substitute the start of a command with something else. They therefore can't use positional parameters, such as `$1`. Rewrite your alias as a function.
### Contraindications ### Exceptions
None. None.

@@ -19,6 +19,6 @@ The problematic code has to iterate the entire directory and read all matching l
The correct code is cleaner and stops at the first matching line, avoiding both iterating the rest of the directory and reading data into memory. The correct code is cleaner and stops at the first matching line, avoiding both iterating the rest of the directory and reading data into memory.
### Contraindications ### Exceptions
The `pipefail` bash option may interfere with this rewrite, since the `if` will now in effect be evaluating the statuses of all commands instead of just the last one. Be careful using them together. The `pipefail` bash option may interfere with this rewrite, since the `if` will now in effect be evaluating the statuses of all commands instead of just the last one. Be careful using them together.

@@ -26,6 +26,6 @@
Instead, use a for loop to expand the glob and check each result individually. Instead, use a for loop to expand the glob and check each result individually.
### Contraindications ### Exceptions
None. None.

@@ -18,6 +18,6 @@ If the intention is to concatenate all the array elements into one argument, use
If the intention is to provide each array element as a separate argument, put the array expansion in its own argument. If the intention is to provide each array element as a separate argument, put the array expansion in its own argument.
### Contraindications ### Exceptions
None. None.

@@ -18,7 +18,7 @@ In other words, the problematic code means "if name matches `*.avi`, do nothing.
In the correct code, we use `\( \)` to group to get the evaluation order we want. The correct code means "if name matches `*.avi` or `*.mkv`, then execute a command", which was what was intended. In the correct code, we use `\( \)` to group to get the evaluation order we want. The correct code means "if name matches `*.avi` or `*.mkv`, then execute a command", which was what was intended.
### Contraindications ### Exceptions
If you're aware of this, you can either ignore this error or group to make it explicit. For example, to decompress all gz files except tar.gz, you can use: If you're aware of this, you can either ignore this error or group to make it explicit. For example, to decompress all gz files except tar.gz, you can use:

@@ -18,6 +18,6 @@ For example, `make` may say `foo: Command not found` even though `foo` works fin
Use `$HOME` or full path instead. Use `$HOME` or full path instead.
### Contraindications ### Exceptions
If your directory name actually contains a literal tilde, you can ignore this message. If your directory name actually contains a literal tilde, you can ignore this message.

@@ -15,6 +15,6 @@ ShellCheck warns about different things for different shells. It uses the sheban
If you don't specify the shell type in any way, ShellCheck assumes a default and gives this message. If you don't specify the shell type in any way, ShellCheck assumes a default and gives this message.
### Contraindications ### Exceptions
None. Just specify the shell type, either in a shebang or as a cli flag. None. Just specify the shell type, either in a shebang or as a cli flag.

@@ -36,6 +36,6 @@ For associative arrays, the `$` should be escaped to avoid accidental dereferenc
echo "$(( array[$index] ))" # bash: array: bad array subscript echo "$(( array[$index] ))" # bash: array: bad array subscript
echo "$(( array[\$index] ))" # 42 echo "$(( array[\$index] ))" # 42
### Contraindications ### Exceptions
None. None.

@@ -23,6 +23,6 @@ If you want `find` to execute a shell command, you have to specify `sh` (or `bas
To prevent command injection, the filename can be passed as a separate argument to sh and referenced as a positional parameter. To prevent command injection, the filename can be passed as a separate argument to sh and referenced as a positional parameter.
### Contraindications ### Exceptions
This warning would trigger falsely if executing a program with spaces in the path, if no other arguments were specified. This warning would trigger falsely if executing a program with spaces in the path, if no other arguments were specified.

@@ -93,6 +93,6 @@ Note that using `+` instead of `\;`, and using an embedded `for file in "$@"` lo
`find -exec` `for i in glob` and `find`+`while` do not rely on word splitting, so they avoid this problem. `find -exec` `for i in glob` and `find`+`while` do not rely on word splitting, so they avoid this problem.
### Contraindications ### Exceptions
If you know about and carefully apply `IFS=$'\n'` and `set -f`, you could choose to ignore this message. If you know about and carefully apply `IFS=$'\n'` and `set -f`, you could choose to ignore this message.

@@ -23,7 +23,7 @@ Trying to fix it by adding quotes or escapes to the data will not work. Instead,
If the command substitution outputs multiple pieces of data, use a loop instead. If the command substitution outputs multiple pieces of data, use a loop instead.
### Contraindications ### Exceptions
In rare cases you actually want word splitting, such as in In rare cases you actually want word splitting, such as in

@@ -16,7 +16,7 @@ Note that `$( )` starts a new context, and variables in it have to be quoted ind
echo "This $variable is quoted $(but this $variable is not)" echo "This $variable is quoted $(but this $variable is not)"
echo "This $variable is quoted $(and now this "$variable" is too)" echo "This $variable is quoted $(and now this "$variable" is too)"
### Contraindications ### Exceptions
Sometimes you want to split on spaces, like when building a command line. Sometimes you want to split on spaces, like when building a command line.
options="-j 5 -B" options="-j 5 -B"

@@ -12,6 +12,6 @@
(An explanation of why the code is problematic and how the correct code is an improvement) (An explanation of why the code is problematic and how the correct code is an improvement)
### Contraindications ### Exceptions
(Cases where the user may choose to ignore this warning, if any.) (Cases where the user may choose to ignore this warning, if any.)