Above answers are correct, but if run script in other folder, there will be some problem.
For example, the a.sh
and b.sh
are in same folder,
a include b with . ./b.sh
to include.
When run script out of the folder, for example with xx/xx/xx/a.sh
, file b.sh
will not found: ./b.sh: No such file or directory
.
I use
. $(dirname "$0")/b.sh