mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2240 (markdown)
30
SC2240.md
Normal file
30
SC2240.md
Normal file
@@ -0,0 +1,30 @@
|
||||
## The dot command does not support arguments in sh/dash. Set them as variables.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
#!/bin/sh
|
||||
. include/myscript example.com 80
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
#!/bin/sh
|
||||
host=example.com port=80 . include/myscript
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
In Bash and Ksh, you can use `. myscript arg1 arg2..` to set `$1` and `$2` in the sourced script.
|
||||
|
||||
This is not the case in Dash, where any additional arguments are ignored, or in POSIX sh where the behavior is unspecified.
|
||||
|
||||
Instead, assign arguments to variables and rewrite the sourced script to read from them.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None.
|
||||
|
||||
### Related resources:
|
||||
|
||||
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user