mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2037 (markdown)
20
SC2037.md
Normal file
20
SC2037.md
Normal file
@@ -0,0 +1,20 @@
|
||||
## To assign the output of a command, use var=$(cmd) .
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
var=grep -c pattern file
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
var=$(grep -c pattern file)
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
To assign the output of a command to a variable, use `$(command substitution)`. Just typing a command after the `=` sign does not work.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None.
|
Reference in New Issue
Block a user