I have the following code snippet, with my question below. As i am completely new to unix, i am not even sure what i should be google searching for to begin with.
I know that ./Path is to run a particular program in the current path
I know also that . /PATH is to run a program in another directory.
But what about . ./PATH ?
if [[ -f ./dbatools.pro ]]; then
. ./dbatools.pro -> **what does this do ? I don’t think such a command is possible ?**
else
. /app/dbatools/profile/dbatools.pro
fi
echo "Started at `date`"
The dot .
command is standard POSIX shell (Bourne, Korn, Bash) notation for 'read the named file as if it was part of the current script'. The big advantage is that the file can set environment variables and define functions and it affects the shell script. Normally, if you run the script as a regular command (using ./dbatools.pro
or sh dbatools.pro
), then the environment variables affect only the shell that executes the script, not the current shell.
The test looks to see if there is a file called dbatools.pro
in the current directory (hence ./dbatools.pro
). If there is, it uses that file; if there is not, then it uses the file /app/dbatools/profile/dbatools.pro
. It will generate an error if it cannot read the file it 'dots'.
With Bash, there's an alternative notation, source ./dbatools.pro
, that can be used instead. It is borrowed from the C shell.
Note that the .
(and source
, a Bash builtin) commands will search for a plain file (. dbatools.pro
, for example) in a directory on $PATH
, but the file does not need to be executable — it only needs to be readable.