The two are completely different, and can not be compared.
./
means the current directory.
. ./
means nothing like as it is, running will print the following error:
-bash: .: ./: is a directory
However, it needs to be broken down in two:
- The
.
command
- The
./
parameter
The .
command is a shell built-in which is a synonym to the source
command. It takes a file and not a directory as a parameter which is why you would get the error above.
A very command example that you might have seen is the following command:
$ . ~/.bashrc
And that is exactly synonym to
$ source ~/.bashrc
You can find their manual by running
man bash-builtins
. filename [arguments]
source filename [arguments]
Read and execute commands from filename in the current shell environment and return
the exit status of the last command executed from filename. If filename does not
contain a slash, filenames in PATH are used to find the directory containing
filename. The file searched for in PATH need not be executable. When bash is not
in posix mode, the current directory is searched if no file is found in PATH. If
the sourcepath option to the shopt builtin command is turned off, the PATH is not
searched. If any arguments are supplied, they become the positional parameters
when filename is executed. Otherwise the positional parameters are unchanged. The
return status is the status of the last command exited within the script (0 if no
commands are executed), and false if filename is not found or cannot be read.
../
works;. ./
wouldn't work. – Jos Nov 27 '20 at 09:06./script.sh
might not run is if you haven't turned on the "execute" bit on. i.e., you would have to do achmod u+x script.sh
first. It depends what error did you get when you tried./script.sh
. Did you get a "permission denied"? – Ray Nov 27 '20 at 09:53./script.sh
. I am guessing the file also doesn't have execute permissions, which is why it cannot be run directly. – Ray Nov 27 '20 at 09:58export.sh
, it isn't any system error. This indicates thatexport.sh
has been specially written to be sourced, and not executed, and is checking this. Probably because - as the name suggests - it exports some variables into the environment, which would have no result if the script were executed, because it would then have it's own temporary environment. Sourcing causes the script run in current shell context (and current environment) without starting a new temporary shell. – raj Nov 27 '20 at 12:54