Linux中执行shell脚本的4种方法

方法一:切换到shell脚本所在的目录(此时,称为工作目录)执行shell脚本:

  1.  cd /data/shell
  2.  ./hello.sh

方法二:以绝对路径的方式去执行bash shell脚本:

        /data/shell/hello.sh

方法三:直接使用bash 或sh 来执行bash shell脚本:

  1.  cd /data/shell
  2.  bash hello.sh

     或

  1.  cd /data/shell
  2.  sh hello.sh

方法四:在当前的shell环境中执行bash shell脚本:

  1.  cd /data/shell
  2.  . hello.sh

     或

  1.  cd /data/shell
  2.  source hello.sh

前三种方法执行shell脚本时都是在当前shell(称为父shell)开启一个子shell环境,此shell脚本就在这个子shell环境中执行。shell脚本执行完后子shell环境随即关闭,然后又回到父shell中。而方法四则是在当前shell中执行的。

       参考文献:https://blog.csdn.net/kitty_landon/article/details/54136352?utm_source=copy

猜你喜欢

转载自www.cnblogs.com/hoboo/p/9759942.html
今日推荐