mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2024 (markdown)
11
SC2024.md
11
SC2024.md
@@ -1,12 +1,16 @@
|
|||||||
## sudo doesn't affect redirects. Use ..| sudo tee file
|
## `sudo` doesn't affect redirects. Use `..| sudo tee file`
|
||||||
|
|
||||||
### Problematic code:
|
### Problematic code:
|
||||||
|
|
||||||
|
```
|
||||||
sudo echo 'export FOO=bar' >> /etc/profile
|
sudo echo 'export FOO=bar' >> /etc/profile
|
||||||
|
```
|
||||||
|
|
||||||
### Correct code:
|
### Correct code:
|
||||||
|
|
||||||
|
```
|
||||||
echo 'export FOO=bar' | sudo tee -a /etc/profile > /dev/null
|
echo 'export FOO=bar' | sudo tee -a /etc/profile > /dev/null
|
||||||
|
```
|
||||||
|
|
||||||
### Rationale:
|
### Rationale:
|
||||||
|
|
||||||
@@ -18,14 +22,17 @@ There is nothing special about `tee`. It's just the simplest command that can bo
|
|||||||
|
|
||||||
Truncating:
|
Truncating:
|
||||||
|
|
||||||
|
```
|
||||||
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:
|
||||||
|
|
||||||
|
```
|
||||||
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'
|
||||||
|
```
|
||||||
|
|
||||||
### Exceptions
|
### Exceptions
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user