zoukankan      html  css  js  c++  java
  • shell各种执行方式区别

    shell 脚本各种执行方式(source ./*.sh, . ./*.sh, ./*.sh)的区别

    原文出处:http://blog.csdn.net/dance_rise/article/details/8573560

    结论一: ./*.sh的执行方式等价于sh ./*.sh或者bash ./*.sh,此三种执行脚本的方式都是重新启动一个子shell,在子shell中执行此脚本(通过fork实现)。

    结论二: .source ./*.sh和 . ./*.sh的执行方式是等价的,即两种执行方式都是在当前shell进程中执行此脚本,而不是重新启动一个shell 而在子shell进程中执行此脚本。

    验证依据:没有被export导出的变量(即非环境变量)是不能被子shell继承的

    验证结果:

        [root@localhost ~]#name=dangxu       //定义一般变量  
        [root@localhost ~]# echo ${name}  
        dangxu  
        [root@localhost ~]# cat test.sh      //验证脚本,实例化标题中的./*.sh  
        #!/bin/sh  
        echo ${name}  
        [root@localhost ~]# ls -l test.sh    //验证脚本可执行  
        -rwxr-xr-x 1 root root 23 Feb  6 11:09 test.sh  
        [root@localhost ~]# ./test.sh        //以下三个命令证明了结论一  
          
        [root@localhost ~]# sh ./test.sh  
          
        [root@localhost ~]# bash ./test.sh  
          
        [root@localhost ~]# . ./test.sh     //以下两个命令证明了结论二  
        dangxu  
        [root@localhost ~]# source ./test.sh  
        dangxu 

  • 相关阅读:
    C connect实现Timeout效果(Linux)
    QSS网址
    C实现读写文件
    crond守护进程实现定时监控某进程占有内存的大小
    Ubuntu17安装Chrome有效
    Ubuntu16安装wine(转)
    直方图均衡化
    函数后面的const修饰符的作用
    C 线程学习记录
    Override Fuction 调用——到底使用的是谁的函数
  • 原文地址:https://www.cnblogs.com/embedded-linux/p/4696441.html
Copyright © 2011-2022 走看看