When running ./a_script
this will look for the script in the current directory. Will run it only if execute permission is given.
When running .a_script
it will search for the hidden script file in $PATH
and run if found.
When running a_script
it will search for the script in $PATH
and run if found.
Yes. Note that the "script" need not be an actual shell script in these cases; any executable will do.
Also, .
is just part of the name of the command here. In ./a_script
it represents the current directory. This works in any path: Try e.g. ls /./home/.
(same as ls /home
).
In a_script
and .a_script
, the command name doesn't contain /
, so a PATH
search is performed. .
isn't special here.
When running . a_script
this will search for the script and run it even if execute permission is not given to the script. Why so?
Because in that case the command is .
and a_script
is just an argument to the .
command. .
will search for the given file and execute the commands in it (in the current shell). a_script
cannot be a general executable; it must be a shell script.
Also, .a_script
and ./a_script
runs the command in the current shell.
No, if they are indeed shell scripts, they will spawn a new shell to run them.
. a_script
runs it is a different shell?
No, it's the opposite: the built-in .
command specifically runs commands from a file in the current shell (as if you had typed them).
Another name for .
is source
, which works the same way, but is easier to search for. See also https://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins.