mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2065 (markdown)
22
SC2065.md
Normal file
22
SC2065.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
## This is interpreted as a shell file redirection, not a comparison.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
[ 3>2 ] || [ 3>'aaa bb' ] # Simple example of problematic code
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
[ 3 -gt 2 ] || [ 3 > 'aaa bb' ] # arithmetical, lexicographical
|
||||||
|
```
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
A word that looks like a redirection in simple shell commands causes it to be interpreted as a redirection.
|
||||||
|
ShellCheck would guess that you don't want it in tests.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
When it's among a continuous list of redirections at the end of a simple `test` command, it's more likely that
|
||||||
|
the user really meant to do a redirection. Or any other case that you mean to do that.
|
Reference in New Issue
Block a user