zoukankan      html  css  js  c++  java
  • shell脚本执行的区别


      1 #!/bin/bash
      2 
      3 . subshell-test.sh
      4 
      5 echo "test.sh"
      6 echo 
      7 echo 
      8 echo $$
      9 echo "$! = $!" 
    
    test.sh 
    

      1 #!/bin/bash
      2 
      3 (echo "Subshell running...";echo " jeffrey is comming...";echo $$)
      4 
      5 echo $!
      6 echo "main..."
      7 echo $$
    
    subshell-test.sh 
    

    . subshell-test.sh: (注意点号后面有个空格)表示读取后面这个shell脚本中的内容在当前脚本中执行. 他不会另起子shell.

    我的理解就是把subshell-test.sh中的内容copy到test.sh中执行。

    因为二者PID是相同的:

    jeffrey@jeffrey-Aspire-4743:~$ ./test.sh 
    Subshell running...
    jeffrey is comming...
    <strong>5196</strong>
    
    main...
    <strong>5196</strong>
    test.sh
    
    
    <strong>5196</strong>
    $! = 



    ./subshell-test.sh:是重新开启新的子shell

    jeffrey@jeffrey-Aspire-4743:~$ ./test.sh 
    Subshell running...
    jeffrey is comming...
    <strong>5214</strong>
    
    main...
    <strong>5214</strong>
    test.sh
    
    
    <strong>5213</strong>
    $! =



  • 相关阅读:
    for else
    改变注释字体颜色
    多继承
    模块的查找顺序
    如何跳出多层嵌套
    验证码书写
    正则表达式(一)
    四、列表与超链接
    三、表格与表单
    二、HTML入门
  • 原文地址:https://www.cnblogs.com/double12gzh/p/10166247.html
Copyright © 2011-2022 走看看