menu

What is the Difference Between Using source and sh

Short Answer:

When you call source (or its alias .), you insert the script in the current bash process. So you could read variables set by the script.

When you call sh, you initiate a fork (sub-process) that runs a new session of /bin/sh, which is usually a symbolic link to bash. In this case, environment variables set by the sub-script would be dropped when the sub-script finishes.

Caution: sh could be a symlink to another shell.

Reference

» what is the difference between using source and sh?



KF

Comments