diff --git a/SC1001.md b/SC1001.md index 27e9789..7debdee 100644 --- a/SC1001.md +++ b/SC1001.md @@ -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`. -### 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. \ No newline at end of file diff --git a/SC1007.md b/SC1007.md index a45a971..157a1e0 100644 --- a/SC1007.md +++ b/SC1007.md @@ -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). -### 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` `` \ No newline at end of file diff --git a/SC1015.md b/SC1015.md index ccd2de7..90e6f68 100644 --- a/SC1015.md +++ b/SC1015.md @@ -14,6 +14,6 @@ Blog software and word processors frequently replaces ASCII quotes `""` with fan 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. \ No newline at end of file diff --git a/SC1016.md b/SC1016.md index a3a8bca..67991d3 100644 --- a/SC1016.md +++ b/SC1016.md @@ -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. -### Contraindications +### Exceptions None \ No newline at end of file diff --git a/SC1035.md b/SC1035.md index d9d594c..a71a8ba 100644 --- a/SC1035.md +++ b/SC1035.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC1037.md b/SC1037.md index 263abbd..18d493b 100644 --- a/SC1037.md +++ b/SC1037.md @@ -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. -### Contraindications +### Exceptions If you wanted the trailing digits to be literal, `${1}0` will make this clear to both humans and shellcheck. \ No newline at end of file diff --git a/SC1040.md b/SC1040.md index 1f84b70..203f942 100644 --- a/SC1040.md +++ b/SC1040.md @@ -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. -### 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. \ No newline at end of file diff --git a/SC1045.md b/SC1045.md index 26e043a..5d1cad3 100644 --- a/SC1045.md +++ b/SC1045.md @@ -14,6 +14,6 @@ Both `&` and `;` terminate the command. You should only use one of them. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC1066.md b/SC1066.md index 512ce43..4001ebb 100644 --- a/SC1066.md +++ b/SC1066.md @@ -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. -### Contraindications +### Exceptions None \ No newline at end of file diff --git a/SC1068.md b/SC1068.md index 76e667e..1583ef5 100644 --- a/SC1068.md +++ b/SC1068.md @@ -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`. -### 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`. \ No newline at end of file diff --git a/SC1077.md b/SC1077.md index 0a1fc8a..5c73e0f 100644 --- a/SC1077.md +++ b/SC1077.md @@ -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. -### Contraindications +### Exceptions If you want to write out literal forward ticks, such as fancyful ascii quotation marks: diff --git a/SC1078.md b/SC1078.md index 1a46d18..8d35a85 100644 --- a/SC1078.md +++ b/SC1078.md @@ -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. -### Contraindications +### Exceptions If you do want a multiline variable, just make sure the character after it is a quote, space or line feed. diff --git a/SC1081.md b/SC1081.md index 125dbad..288e056 100644 --- a/SC1081.md +++ b/SC1081.md @@ -18,6 +18,6 @@ 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`. \ No newline at end of file diff --git a/SC1083.md b/SC1083.md index ac2092d..a53e8fe 100644 --- a/SC1083.md +++ b/SC1083.md @@ -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. -### 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}'`. \ No newline at end of file diff --git a/SC1084.md b/SC1084.md index cbf46a1..b74f6c4 100644 --- a/SC1084.md +++ b/SC1084.md @@ -14,6 +14,6 @@ The shebang has been accidentally swapped. The `#` should come first: `#!`, not `!#`. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC1086.md b/SC1086.md index bd5ab16..243e4b4 100644 --- a/SC1086.md +++ b/SC1086.md @@ -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). -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC1087.md b/SC1087.md index 4f74522..35817f0 100644 --- a/SC1087.md +++ b/SC1087.md @@ -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. -### 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. \ No newline at end of file diff --git a/SC2001.md b/SC2001.md index 4c0df3c..98a3512 100644 --- a/SC2001.md +++ b/SC2001.md @@ -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. -### Contraindications +### Exceptions Occasionally a more complex sed substitution is required. For example, getting the last character of a string. diff --git a/SC2002.md b/SC2002.md index e893980..125d01a 100644 --- a/SC2002.md +++ b/SC2002.md @@ -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`. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2003.md b/SC2003.md index 35efdf5..59019d8 100644 --- a/SC2003.md +++ b/SC2003.md @@ -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. -### 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. diff --git a/SC2006.md b/SC2006.md index 78955fa..f05acc9 100644 --- a/SC2006.md +++ b/SC2006.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2009.md b/SC2009.md index be0b5cb..9d3eb8a 100644 --- a/SC2009.md +++ b/SC2009.md @@ -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. -### Contraindications +### Exceptions What if you have the pid and you are looking for the matching program name? diff --git a/SC2013.md b/SC2013.md index 09db7c1..738f52e 100644 --- a/SC2013.md +++ b/SC2013.md @@ -43,7 +43,7 @@ The while loop will print: 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). diff --git a/SC2015.md b/SC2015.md index c8072e6..44035ea 100644 --- a/SC2015.md +++ b/SC2015.md @@ -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. -### Contraindications +### Exceptions Ignore this warning when you actually do intend to run C when either A or B fails. \ No newline at end of file diff --git a/SC2016.md b/SC2016.md index e23f5ff..ef14f7d 100644 --- a/SC2016.md +++ b/SC2016.md @@ -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. -### Contraindications +### Exceptions If you want `$stuff` to be a literal dollar sign followed by the characters "stuff", you can ignore this message. diff --git a/SC2020.md b/SC2020.md index 3e326f5..1fa8c56 100644 --- a/SC2020.md +++ b/SC2020.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2022.md b/SC2022.md index 72233e0..91dbd65 100644 --- a/SC2022.md +++ b/SC2022.md @@ -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. -### 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]*'`. \ No newline at end of file diff --git a/SC2024.md b/SC2024.md index e9b5831..41308e5 100644 --- a/SC2024.md +++ b/SC2024.md @@ -27,6 +27,6 @@ Appending: 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. \ No newline at end of file diff --git a/SC2025.md b/SC2025.md index 0e6ff1d..e6a8edd 100644 --- a/SC2025.md +++ b/SC2025.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2026.md b/SC2026.md index 41b2a23..3fbb4ce 100644 --- a/SC2026.md +++ b/SC2026.md @@ -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" 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. \ No newline at end of file diff --git a/SC2027.md b/SC2027.md index cfac0e3..330becb 100644 --- a/SC2027.md +++ b/SC2027.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2028.md b/SC2028.md index 86ecc37..316c750 100644 --- a/SC2028.md +++ b/SC2028.md @@ -20,6 +20,6 @@ If you actually wanted a literal backslash-t, use echo "\\t" -### Contraindications +### Exceptions None \ No newline at end of file diff --git a/SC2029.md b/SC2029.md index 2d3ec69..5591a4f 100644 --- a/SC2029.md +++ b/SC2029.md @@ -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. -### Contraindications +### Exceptions If you do want your string expanded on the client side, you can safely ignore this message. diff --git a/SC2031.md b/SC2031.md index 063b68d..61854a1 100644 --- a/SC2031.md +++ b/SC2031.md @@ -55,6 +55,6 @@ Anything executed by external processes: 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. \ No newline at end of file diff --git a/SC2033.md b/SC2033.md index 9c81f89..f24323d 100644 --- a/SC2033.md +++ b/SC2033.md @@ -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. -### 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. diff --git a/SC2034.md b/SC2034.md index 862354b..9c485c4 100644 --- a/SC2034.md +++ b/SC2034.md @@ -14,7 +14,7 @@ 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). diff --git a/SC2038.md b/SC2038.md index 8006a80..5ca762b 100644 --- a/SC2038.md +++ b/SC2038.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2043.md b/SC2043.md index 99bc7cd..cfa7395 100644 --- a/SC2043.md +++ b/SC2043.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2048.md b/SC2048.md index e955c88..0ee828d 100644 --- a/SC2048.md +++ b/SC2048.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2051.md b/SC2051.md index 607f9f4..bc6c8f3 100644 --- a/SC2051.md +++ b/SC2051.md @@ -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")") -### Contraindications +### Exceptions None (if you're writing for e.g. zsh, make sure the shebang indicates this so shellcheck won't warn) \ No newline at end of file diff --git a/SC2055.md b/SC2055.md index f44d4e4..5b8a873 100644 --- a/SC2055.md +++ b/SC2055.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2059.md b/SC2059.md index ab8a292..addf474 100644 --- a/SC2059.md +++ b/SC2059.md @@ -20,7 +20,7 @@ The first printf writes `Unit test coverage: 96%`. The second writes ``bash: printf: `\': invalid format character`` -### Contraindications +### Exceptions Sometimes you may actually want to interpret data as a format string, like in: diff --git a/SC2060.md b/SC2060.md index d8ba88f..41acf35 100644 --- a/SC2060.md +++ b/SC2060.md @@ -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. -### Contraindications +### Exceptions None \ No newline at end of file diff --git a/SC2063.md b/SC2063.md index 9f9dd7d..374ae43 100644 --- a/SC2063.md +++ b/SC2063.md @@ -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". -### Contraindications +### Exceptions If you're aware of the differences between globs and regex, you can ignore this message. \ No newline at end of file diff --git a/SC2064.md b/SC2064.md index 88b1401..8d0d9f7 100644 --- a/SC2064.md +++ b/SC2064.md @@ -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. -### 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. \ No newline at end of file diff --git a/SC2066.md b/SC2066.md index b242b8e..f84bea1 100644 --- a/SC2066.md +++ b/SC2066.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2067.md b/SC2067.md index 2165b2f..3e4706d 100644 --- a/SC2067.md +++ b/SC2067.md @@ -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). -### Contraindications +### Exceptions None \ No newline at end of file diff --git a/SC2068.md b/SC2068.md index aa64b2b..839c030 100644 --- a/SC2068.md +++ b/SC2068.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2069.md b/SC2069.md index 375f379..5da3260 100644 --- a/SC2069.md +++ b/SC2069.md @@ -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. -### Contraindications +### Exceptions If you want stderr as stdout and stdout to a file, you can ignore this message. \ No newline at end of file diff --git a/SC2072.md b/SC2072.md index 6c52201..b7c05e6 100644 --- a/SC2072.md +++ b/SC2072.md @@ -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. -### 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. \ No newline at end of file diff --git a/SC2077.md b/SC2077.md index 88d2983..a22260e 100644 --- a/SC2077.md +++ b/SC2077.md @@ -16,6 +16,6 @@ Always use spaces around the comparison operator in `[..]` and `[[..]]`, otherwise it won't be recognized as an operator. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2088.md b/SC2088.md index bc66ac6..add2af1 100644 --- a/SC2088.md +++ b/SC2088.md @@ -27,6 +27,6 @@ These strings do not, leaving a literal tilde: ~"/file" # 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. \ No newline at end of file diff --git a/SC2089.md b/SC2089.md index a3e8ecb..3d57b88 100644 --- a/SC2089.md +++ b/SC2089.md @@ -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 /`. -### Contraindications +### Exceptions Few and far between. \ No newline at end of file diff --git a/SC2094.md b/SC2094.md index c9cf5d5..fd849b9 100644 --- a/SC2094.md +++ b/SC2094.md @@ -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. -### Contraindications +### Exceptions You can ignore this error if: diff --git a/SC2096.md b/SC2096.md index 53cd477..9c7e1a8 100644 --- a/SC2096.md +++ b/SC2096.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2097.md b/SC2097.md index d6af7d0..2c62b5e 100644 --- a/SC2097.md +++ b/SC2097.md @@ -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. -### 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. \ No newline at end of file diff --git a/SC2101.md b/SC2101.md index 1d05034..4c4aaf3 100644 --- a/SC2101.md +++ b/SC2101.md @@ -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. -### 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:]'` \ No newline at end of file diff --git a/SC2103.md b/SC2103.md index 644afdc..c3bf107 100644 --- a/SC2103.md +++ b/SC2103.md @@ -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`. -### Contraindications +### Exceptions None known. \ No newline at end of file diff --git a/SC2116.md b/SC2116.md index 711efcf..caddbf7 100644 --- a/SC2116.md +++ b/SC2116.md @@ -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! -### Contraindications +### Exceptions None I am aware of at the moment. \ No newline at end of file diff --git a/SC2117.md b/SC2117.md index e230015..591ea48 100644 --- a/SC2117.md +++ b/SC2117.md @@ -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. -### 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. \ No newline at end of file diff --git a/SC2120.md b/SC2120.md index 20f419d..d51a80c 100644 --- a/SC2120.md +++ b/SC2120.md @@ -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"; } first "$@" -### Contraindications +### Exceptions If the parameters are optional and you currently just don't want to use them, you can ignore this message. diff --git a/SC2121.md b/SC2121.md index e4b8bcc..9106366 100644 --- a/SC2121.md +++ b/SC2121.md @@ -15,6 +15,6 @@ 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"`. \ No newline at end of file diff --git a/SC2122.md b/SC2122.md index 43cdac4..7ac4baf 100644 --- a/SC2122.md +++ b/SC2122.md @@ -12,6 +12,6 @@ The operators `<=` and `>=` are not supported by Bourne shells. Instead of "less than or equal", rewrite as "not greater than". -### Contraindications +### Exceptions None \ No newline at end of file diff --git a/SC2123.md b/SC2123.md index 88ee202..7c59793 100644 --- a/SC2123.md +++ b/SC2123.md @@ -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. -### 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. \ No newline at end of file diff --git a/SC2124.md b/SC2124.md index 91c490a..2941551 100644 --- a/SC2124.md +++ b/SC2124.md @@ -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). -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2125.md b/SC2125.md index 815ca1e..4b48d6a 100644 --- a/SC2125.md +++ b/SC2125.md @@ -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"`). -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2128.md b/SC2128.md index c74a890..0e434f2 100644 --- a/SC2128.md +++ b/SC2128.md @@ -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"`. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2129.md b/SC2129.md index 6183038..06552bc 100644 --- a/SC2129.md +++ b/SC2129.md @@ -19,6 +19,6 @@ 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. \ No newline at end of file diff --git a/SC2130.md b/SC2130.md index 6f31cc8..0b0eb8b 100644 --- a/SC2130.md +++ b/SC2130.md @@ -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. -### Contraindications +### Exceptions None. diff --git a/SC2139.md b/SC2139.md index df172a0..32e1228 100644 --- a/SC2139.md +++ b/SC2139.md @@ -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. -### Contraindications +### Exceptions If you don't mind that your alias definition is expanded at define time, you can ignore this warning. \ No newline at end of file diff --git a/SC2140.md b/SC2140.md index 5731c9f..940b2a7 100644 --- a/SC2140.md +++ b/SC2140.md @@ -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. -### Contraindications +### Exceptions If you know that the quotes are ineffectual but you prefer it stylistically, you can ignore this message. \ No newline at end of file diff --git a/SC2141.md b/SC2141.md index 4a103b9..fb35a19 100644 --- a/SC2141.md +++ b/SC2141.md @@ -12,6 +12,6 @@ `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. \ No newline at end of file diff --git a/SC2142.md b/SC2142.md index e1149bf..a1642c7 100644 --- a/SC2142.md +++ b/SC2142.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2143.md b/SC2143.md index fe5dbda..9e9df2c 100644 --- a/SC2143.md +++ b/SC2143.md @@ -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. -### 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. \ No newline at end of file diff --git a/SC2144.md b/SC2144.md index de8bd36..6011309 100644 --- a/SC2144.md +++ b/SC2144.md @@ -26,6 +26,6 @@ Instead, use a for loop to expand the glob and check each result individually. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2145.md b/SC2145.md index 290ac4f..8ef3e4d 100644 --- a/SC2145.md +++ b/SC2145.md @@ -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. -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2146.md b/SC2146.md index 8a1b4ee..7a0f296 100644 --- a/SC2146.md +++ b/SC2146.md @@ -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. -### 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: diff --git a/SC2147.md b/SC2147.md index 48e1881..d9c5ef5 100644 --- a/SC2147.md +++ b/SC2147.md @@ -18,6 +18,6 @@ For example, `make` may say `foo: Command not found` even though `foo` works fin Use `$HOME` or full path instead. -### Contraindications +### Exceptions If your directory name actually contains a literal tilde, you can ignore this message. \ No newline at end of file diff --git a/SC2148.md b/SC2148.md index b7ce259..5bdff2c 100644 --- a/SC2148.md +++ b/SC2148.md @@ -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. -### Contraindications +### Exceptions None. Just specify the shell type, either in a shebang or as a cli flag. \ No newline at end of file diff --git a/SC2149.md b/SC2149.md index f21e70f..84f72fb 100644 --- a/SC2149.md +++ b/SC2149.md @@ -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] ))" # 42 -### Contraindications +### Exceptions None. \ No newline at end of file diff --git a/SC2150.md b/SC2150.md index 05b452a..8a655ba 100644 --- a/SC2150.md +++ b/SC2150.md @@ -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. -### Contraindications +### Exceptions This warning would trigger falsely if executing a program with spaces in the path, if no other arguments were specified. \ No newline at end of file diff --git a/Sc2044.md b/Sc2044.md index 18c1749..d75ff36 100644 --- a/Sc2044.md +++ b/Sc2044.md @@ -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. -### Contraindications +### Exceptions If you know about and carefully apply `IFS=$'\n'` and `set -f`, you could choose to ignore this message. \ No newline at end of file diff --git a/Sc2046.md b/Sc2046.md index a705c63..fdd14d3 100644 --- a/Sc2046.md +++ b/Sc2046.md @@ -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. -### Contraindications +### Exceptions In rare cases you actually want word splitting, such as in diff --git a/Sc2086.md b/Sc2086.md index 310b7a7..844516e 100644 --- a/Sc2086.md +++ b/Sc2086.md @@ -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 $(and now this "$variable" is too)" -### Contraindications +### Exceptions Sometimes you want to split on spaces, like when building a command line. options="-j 5 -B" diff --git a/Template.md b/Template.md index 20056a6..45d9e13 100644 --- a/Template.md +++ b/Template.md @@ -12,6 +12,6 @@ (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.) \ No newline at end of file