0

In Linux shell, I've seen the command starting with "./" e.g.

$ ./example

But then I've also seen the similar command like $ . example.sh

My question is do they have the same function?

1

./example.sh will execute example.sh in the current directory.

. example.sh will source example.sh.

1

Although they may looking similar both commands are not related.

./example

will execute a binary or executable shell script in the current folder. If it is a shell script it will being executed in a sub shell.


. example

is identical to

source example

which will "source" the file, meaning executing it in the context of the current shell. This means if there are variable or function declarations in that file they will be available in the current shell after the source command. Also variable manipulations or whatever will happen in the current shell. It is just like if you would have typed the content of the file line by line manually in the terminal.

Not the answer you're looking for? Browse other questions tagged or ask your own question.