0

Both of two lines below seems to execute my_script. What's the difference between the two processes?

$ bash my_script
$ source my_script
Jack Chen
  • 169
  • Also see: https://unix.stackexchange.com/questions/270966/what-is-the-difference-between-using-bash-and-sh-to-run-a-script – muru Jun 16 '19 at 06:36

1 Answers1

0

A major different is that bash runs in a subprocess, while source is as if you are running the content:

$ cat my_script
echo $$
$ bash my_script
85183
$ source my_script
1581
$ echo $$
1581
muru
  • 72,889