source command not found in sh shell
/bin/sh
is usually some other shell trying to mimic The Shell. Many distributions use /bin/bash
for sh
, it supports source
. On Ubuntu, though, /bin/dash
is used which does not support source
. Most shells use .
instead of source
. If you cannot edit the script, try to change the shell which runs it.
$ls -l `which sh`
/bin/sh -> dash
$sudo dpkg-reconfigure dash #Select "no" when you're asked
[...]
$ls -l `which sh`
/bin/sh -> bash
Then it will be OK
The source
builtin is a bashism. Write this simply as .
instead.
e.g.
. $FILE
# OR you may need to use a relative path (such as in an `npm` script):
. ./$FILE
https://wiki.ubuntu.com/DashAsBinSh#source
In Bourne shell(sh), use the . command to source a file
. filename
In certain OS's/environments (Mac OS, Travis-CI, Ubuntu, at least) this must be:
. ./filename
(Credit to Adrien Joly's comment below)