mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC1048 (markdown)
29
SC1048.md
Normal file
29
SC1048.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
## Can't have empty then clauses (use 'true' as a no-op).
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
if [ -e foo ]
|
||||||
|
then
|
||||||
|
# TODO: handle this
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
if [ -e foo ]
|
||||||
|
then
|
||||||
|
# TODO: handle this
|
||||||
|
true
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
Shells do not allow empty `then` clauses. They need at least one command (and comments are not commands).
|
||||||
|
|
||||||
|
If you want a `then` clause that does nothing, use a dummy command like `true`.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None.
|
Reference in New Issue
Block a user