In Linux shell, I've seen the command starting with "./" e.g.
But then I've also seen the similar command like $ . example.sh
My question is do they have the same function?
./example.sh will execute
example.sh in the current directory.
. example.sh will source
Although they may looking similar both commands are not related.
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.
is identical to
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.