mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2024 (markdown)
10
SC2024.md
10
SC2024.md
@@ -6,7 +6,7 @@ or "Use `sudo cat file | ..`" instead of `<` to read.
|
|||||||
|
|
||||||
### Problematic code:
|
### Problematic code:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
# Write to a file
|
# Write to a file
|
||||||
sudo echo 3 > /proc/sys/vm/drop_caches
|
sudo echo 3 > /proc/sys/vm/drop_caches
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ sudo wc -l < /etc/shadow
|
|||||||
|
|
||||||
### Correct code:
|
### Correct code:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
# Write to a file
|
# Write to a file
|
||||||
echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null
|
echo 3 | sudo tee /proc/sys/vm/drop_caches > /dev/null
|
||||||
|
|
||||||
@@ -45,14 +45,14 @@ Note: there is nothing special about `tee`. It's just the simplest command that
|
|||||||
|
|
||||||
Truncating:
|
Truncating:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
echo 'data' | sudo dd of=file
|
echo 'data' | sudo dd of=file
|
||||||
echo 'data' | sudo sed 'w file'
|
echo 'data' | sudo sed 'w file'
|
||||||
```
|
```
|
||||||
|
|
||||||
Appending:
|
Appending:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
echo 'data' | sudo awk '{ print $0 >> "file" }'
|
echo 'data' | sudo awk '{ print $0 >> "file" }'
|
||||||
echo 'data' | sudo sh -c 'cat >> file'
|
echo 'data' | sudo sh -c 'cat >> file'
|
||||||
```
|
```
|
||||||
|
Reference in New Issue
Block a user