Skip to content
Vidar Holen edited this page Nov 8, 2018 · 1 revision

The dot command does not support arguments in sh/dash. Set them as variables.

Problematic code:

#!/bin/sh
. include/myscript example.com 80

Correct code:

#!/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!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally