0

What is the difference between the following two commands to source a file and then print the env variables?

sh -c . envvars.sh; env

And:

./envvars.sh; env

More specifically, what do the following do:

". envvars.sh" vs. "./envvars.sh"

And:

"sh -c envvars.sh" and "./envvars.sh"
FI-Info
  • 635
  • 7
  • 16
  • 4
    Did you already read https://ss64.com/bash/source.html by any chance? It explains what the difference is between sourcing and just executing the script. – Felix Kling Oct 19 '19 at 20:21
  • `sh -c . envvars.sh` doesn't even pass `envvars.sh` as an argument to `.`; it *completely ignores* that argument, and thus causes `.` to fail with a usage error. You probably meant `sh -c '. envvars.sh'`; the quoting is not optional. – Charles Duffy Oct 19 '19 at 23:27

0 Answers0