慎用. 或 source去执行脚本

一般情况下,从书上我们可以知道 可以使用.或者是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去执行脚本,除非你确认是有必要的

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值