一般情况下,从书上我们可以知道 可以使用.或者是source 去执行当前目录下的脚本,但是这种情况需要注意,
因为很可能在环境变量PATH所包含的目录下也有和你同名的脚本或者其他可执行程序,那么实际执行就不会执行你当前的目录下的那个脚本。
在手册上是这么写的,可以仔细看看。
. 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, file names 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 file-
name is not found or cannot be read.
这里举个例子:
比如在/home/chlaws下,
mkdir test;
cd test
cat > test.sh (注意ctrl + d结束输入)
#/bin/bash
echo `pwd`
echo $PATH,里面随便找一个目录
cp $HOME/test/test.sh /usr/local/bin
这是,使用.去执行脚本
. test.sh
那么这里会显示的是/usr/local/bin,而不是你当前所在的路径。
如果在/usr/local/bin/test.sh中包含大量的修改,删除操作,那么执行之后你会悲剧的。。
因此,这里非常需要注意。不要用. 或者是 source去执行脚本,除非你确认是有必要的