mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
Updated SC2024 (markdown)
13
SC2024.md
13
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:
|
||||
|
||||
```
|
||||
sudo echo 'export FOO=bar' >> /etc/profile
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```
|
||||
echo 'export FOO=bar' | sudo tee -a /etc/profile > /dev/null
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
|
||||
@@ -18,15 +22,18 @@ There is nothing special about `tee`. It's just the simplest command that can bo
|
||||
|
||||
Truncating:
|
||||
|
||||
```
|
||||
echo 'data' | sudo dd of=file
|
||||
echo 'data' | sudo sed 'w file'
|
||||
```
|
||||
|
||||
Appending:
|
||||
|
||||
```
|
||||
echo 'data' | sudo awk '{ print $0 >> "file" }'
|
||||
echo 'data' | sudo sh -c 'cat >> file'
|
||||
|
||||
```
|
||||
|
||||
### Exceptions
|
||||
|
||||
If you want to run a command as root but redirect as the normal user, you can ignore this message.
|
||||
If you want to run a command as root but redirect as the normal user, you can ignore this message.
|
||||
|
Reference in New Issue
Block a user