mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC3034 (markdown)
29
SC3034.md
Normal file
29
SC3034.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
## In POSIX sh, $(<file) is undefined.
|
||||||
|
|
||||||
|
(or "In dash, ... is not supported." when using `dash`)
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
content=$(<file)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
content=$(cat file)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
In bash and ksh, `$(< file)` will expand to the full contents of the file.
|
||||||
|
|
||||||
|
However, in dash and POSIX sh, it will instead expand to nothing. This is because it's not recognized as special, and simply results in the command output of `< file`, a no-op command that opens the file and exits without reading it.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None.
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user