shell 中调用其他的脚本
2013-09-05 18:12
323 查看
方法有三种:
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
所以在调用的那个脚本需要传递参数的时候还是要注意选对方法的
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
所以在调用的那个脚本需要传递参数的时候还是要注意选对方法的
相关文章推荐
- python调用Shell脚本(或其他脚本比如python)
- 9、在Shell脚本中调用其他脚本
- linux -- shell脚本调用其他脚本,向shell脚本传递参数
- shell 后台执行以及隐藏脚本中调用其他脚本隐藏输出
- shell脚本读取文本文件调用其他脚本传递获取参数
- shell脚本中调用其他脚本
- shell .bashrc中函数在其他脚本无法调用问题
- WScript.Shell对象的run和exec(脚本调用其他程序)
- 9、在Shell脚本中调用其他脚本
- shell脚本调用多个jar
- 深入浅出Power Shell——cmd调用PowerShell脚本
- 在shell脚本中调用另一个脚本的三种不同方法(fork, exec, source)
- C程序调用shell脚本共有三种方法
- C语言中system调用shell脚本的问题
- c++中调用其他应用程序的方法winexec shellexecute createprocess
- c语言中调用shell脚本返回值问题分析
- Nodejs中调用系统命令、Shell脚本和Python脚本的方法和实例
- 分享一个遍历当前文件夹下所以子目录,并在子目录中执行其他操作的shell脚本
- C程序调用shell脚本共有三种方法
- python的subprocess:子程序调用(调用执行其他命令);获取子程序脚本当前路径问题