方法有三种:

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

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

shell 中调用其他的脚本的更多相关文章

  1. Shell中 调用/引用/包含 另外的脚本文件的两种方法

    脚本 first (测试示例1) #!/bin/bash echo 'your are in first file' 问)在当前脚本文件中调用另外一个脚本文件? 方法一: 使用 source 脚本 s ...

  2. shell中调用R语言并传入参数的两种步骤

    shell中调用R语言并传入参数的两种方法 第一种: Rscript myscript.R R脚本的输出 第二种: R CMD BATCH myscript.R # Check the output ...

  3. shell中调用jenkins API批量运行历史任务

    shell中调用jenkins API批量运行jenkins带参数的任务: #!/bin/sh #startdate=20150127 startdate=20150201 while [ " ...

  4. shell 获得调用的python脚本的print值和错误log

    1. shell 获得调用的python脚本的print值 python test.py > out.log 2.shell 获得调用的python脚本的错误log python test.py ...

  5. Linux/Unix shell 脚本中调用SQL,RMAN脚本

    Linux/Unix shell脚本中调用或执行SQL,RMAN 等为自动化作业以及多次反复执行提供了极大的便利,因此通过Linux/Unix shell来完成Oracle的相关工作,也是DBA必不可 ...

  6. shell脚本中调用另一个脚本的三种不同方法(fork, exec, source)

    fork ( /directory/script.sh) fork是最普通的, 就是直接在脚本里面用/directory/script.sh来调用script.sh这个脚本. 运行的时候开一个sub- ...

  7. 在shell脚本中调用另一个脚本的三种不同方法(fork, exec, source)——转载

    原文链接:http://blog.chinaunix.net/uid-22548820-id-3181798.html fork ( /directory/script.sh) :如果shell中包含 ...

  8. Shell脚本中调用另外一个脚本的方法

    (转载): 在Linux平台上开发,经常会在console(控制台)上执行另外一个脚本文件,经常用的方法有:./my.sh 或 source my.sh 或 . my.sh:这三种方法有什么不同呢?我 ...

  9. Linux脚本中调用SQL,RMAN脚本

    Linux/Unix shell脚本中调用或执行SQL,RMAN 等为自动化作业以及多次反复执行提供了极大的便利,因此通过Linux/Unix shell来完成Oracle的相关工作,也是DBA必不可 ...

随机推荐

  1. 《我是一只IT小小鸟》读书笔记

    大一进来的第一个学期 我对我所读的软件工程专业感到迷茫与不知.就这么昏昏沉沉的度过了一个学期,第二个学期一开始,在上第一节新增加的“大学生创业与指导”课程充满了好奇,在课上老师推荐的一本书<我是 ...

  2. 关于 一开始不懂得 hosts配置。

    是转载别人的. 原文: http://my.oschina.net/cxz001/blog/298228   感谢分享: 一开始抄着陪着win下的hosts文件.然后配置  apache中的hosts ...

  3. grep命令学习

    grep(Globally search a Regular Expression and Print), 全面搜索正则表达式并把行打印出来,是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把 ...

  4. <%@page contentType="text/html;charset=gbk"%>与<meta http-equiv="Content-Type" content="text/html; charset=GBK">区别

    前一个是在服务端起作用,是告诉应用服务器采用何种编码输出JSP文件流,后一个是在客户端起作用,是告诉浏览器是采用何种编码方式显示HTML页面.     前者由jsp引擎对输出内容进行编码, 后者将由I ...

  5. android 学习资源总结

    http://android-arsenal.com/free   国外的android分类资源网站 http://www.ibm.com/developerworks/cn/topics/   IB ...

  6. .net frameworkAPI文档下载地址

    http://www.msdn.hk/html/2014/5.html VS2013 ILdasm 反编译工具安装在下面地址里了 C:\Program Files (x86)\Microsoft SD ...

  7. 移动web

    1.分辨率 1900*1200这就是一个分辨率, 因为pt的存在,因此还会有一个逻辑分辨率的概念 2.ppi = pixels per inch这里inch不是平方英尺,是英尺 3.dp = devi ...

  8. select for update行锁

     select for update行锁 2008-05-26 15:15:37 分类: Oracle Select-For Update语句的语法与select语句相同,只是在select语句的后面 ...

  9. 存储过程procedure

                       存储过程(procedure) 修改mysql结束符   delimiter name procedure创建语法:     create procedure p ...

  10. MVC 下 JsonResult 的使用方法(JsonRequestBehavior.AllowGet)【转】

    MVC 默认 Request 方式为Get. actionpublic JsonResult GetPersonInfo(){var person = new{Name = "张三" ...