zoukankan      html  css  js  c++  java
  • shell 中调用其他的脚本

    方法有三种:

    1 使用source

    2 使用 .

    3 使用sh

    简单实验:

    first.sh

    #!/bin/bash
    echo 'your are in first file'

    second.sh

    #!/bin/bash
    echo 'your are in second file'

    source first.sh // . first.sh // sh first.sh

    执行结果:

    your are in second file
    your are in first file

    现在讨论关于参数传递:

    first.sh

    #!/bin/bash
    echo 'your are in first file'
    echo "${0} ${1}"

    second.sh

    #!/bin/bash
    echo 'your are in second file'
    echo "${0} ${1}"

    . first.sh ${2} //source first.sh

    执行:./second.sh abc 123

    your are in second file
    ./second.sh abc
    your are in first file
    ./second.sh 123

    改变second.sh

    second.sh

    #!/bin/bash
    echo 'your are in second file'
    echo "${0} ${1}"

    sh first.sh ${2} 

    执行:

    ./second.sh abc 123

    结果:

    your are in second file
    ./second.sh abc
    your are in first file
    first.sh 123

    所以在调用的那个脚本需要传递参数的时候还是要注意选对方法的

  • 相关阅读:
    实验
    ls -l 详解
    实验
    B
    2.02_Python网络爬虫分类及其原理
    2.01_Python网络爬虫概述
    DA_03_linux网络配置及其远程连接
    DA_01_linux_物理机局域网工作机制
    Hadoop_01_Apache Hadoop概述
    13_Redis_持久化
  • 原文地址:https://www.cnblogs.com/michile/p/3303884.html
Copyright © 2011-2022 走看看