mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2114 (markdown)
23
SC2114.md
Normal file
23
SC2114.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
## Warning: deletes a system directory. Use 'rm --' to disable this message.
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
rm -rf /usr /lib/nvidia-current/xorg/xorg
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
rm -rf /usr/lib/nvidia-current/xorg/xorg
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
The example line of code was an actual bug in the [Bumblebee NVIDIA driver](https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/commit/a047be85247755cdbe0acce6f1dafc8beb84f2ac).
|
||||||
|
|
||||||
|
Due to an accidental space, it deleted `/usr` instead of just the particular directory.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
In cases of chroot, initramfs and similar, it's reasonable to delete otherwise important directories. Due to this, Shellcheck will not warn if the command contains `--`:
|
||||||
|
|
||||||
|
rm -rf -- /usr
|
||||||
|
|
||||||
|
This is an arbitrary convention to allow deleting such directories without having to use a [[directive]] to silence the warning.
|
Reference in New Issue
Block a user