mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC1010 (markdown)
@@ -1,5 +1,7 @@
|
||||
## Use semicolon or linefeed before 'done' (or quote to make it literal).
|
||||
|
||||
(or `do` `then`, `fi`, `esac`)
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```
|
||||
@@ -26,9 +28,9 @@ echo "$f is done"
|
||||
|
||||
### Rationale:
|
||||
|
||||
`done` only works as a keyword when it's the first token of the command. If added after a command, it will just be the literal word "done".
|
||||
ShellCheck found a keyword like `done`, `then`, `fi`, `esac`, etc used as the argument of a command. This means that the shell will interpret it as a literal string rather than a shell keyword. To be interpreted as a keyword, it must be the first word in the line (i.e. after `;`, `&` or a linefeed).
|
||||
|
||||
This is also true for other keywords like `then`.
|
||||
In the example, `echo "$f" done` is the same as `echo "$f" "done"`, and the `done` does not terminate the loop. This is fixed by terminating the `echo` command with a `;` so that the `done` is the first word in the next line.
|
||||
|
||||
### Exceptions
|
||||
|
||||
|
Reference in New Issue
Block a user