关于两种运行sh的方式: ./myscript.ksh and . ./myscript.ksh
2012-01-10 16:49
399 查看
这个问题困扰我很久很久了。。。有时候用这个就行,有时候用那个才行,到底有什么区别?
Difference Between executing like ./myscript.ksh and . ./myscript.ksh (两个点之间有空格)
我参考了下面这两篇帖子:
http://www.unix.com/unix-dummies-questions-answers/156460-difference-between-executing-llike-myscript-ksh-myscript-ksh.html http://publib.boulder.ibm.com/infocenter/zvm/v5r4/index.jsp?topic=/com.ibm.zvm.v54.dmsp3/comd672.htm
. myscript.ksh的意思是,Run a shell file in the current environment。
也就是说executes ksh in current shell. Since it's run in the current shell, any variables it sets, for example, are available in your current shell.
但我们常用的形式是. ./myscript.ksh (中间有空格). 这是因为文件名的缘故:
If there are slashes in the file name, . (dot) looks for the named file. If there are no slashes
. (dot) uses the search PATH variableto find
file.
This may surprise some people when they use dot torun a file in the working directory, but their search rules are not set upto look at the working directory. As a result, the shell doesn't find theshell file. If you have this problem, you can use:
. ./myscript.ksh
因此上句的意思就是,使用current environment运行这个脚本,同时,在工作目录搜索该脚本。
所以现在很清楚了, ./myscript.ksh的意思是执行当前工作目录中的这个脚本,但是是在不同的shell中。
二者的不同会导致一个明显的区别:
如果在一个ksh中设置了一些变量,然后调用了:
ksh `. ./myscript.ksh` 那么之前设置的变量可以在子脚本,即myscript.ksh中使用。
如果调用的是:
ksh `./myscript.ksh` 那么之前设置的变量不能在myscript.ksh中使用。
Difference Between executing like ./myscript.ksh and . ./myscript.ksh (两个点之间有空格)
我参考了下面这两篇帖子:
http://www.unix.com/unix-dummies-questions-answers/156460-difference-between-executing-llike-myscript-ksh-myscript-ksh.html http://publib.boulder.ibm.com/infocenter/zvm/v5r4/index.jsp?topic=/com.ibm.zvm.v54.dmsp3/comd672.htm
. myscript.ksh的意思是,Run a shell file in the current environment。
也就是说executes ksh in current shell. Since it's run in the current shell, any variables it sets, for example, are available in your current shell.
但我们常用的形式是. ./myscript.ksh (中间有空格). 这是因为文件名的缘故:
If there are slashes in the file name, . (dot) looks for the named file. If there are no slashes
. (dot) uses the search PATH variableto find
file.
This may surprise some people when they use dot torun a file in the working directory, but their search rules are not set upto look at the working directory. As a result, the shell doesn't find theshell file. If you have this problem, you can use:
. ./myscript.ksh
因此上句的意思就是,使用current environment运行这个脚本,同时,在工作目录搜索该脚本。
所以现在很清楚了, ./myscript.ksh的意思是执行当前工作目录中的这个脚本,但是是在不同的shell中。
二者的不同会导致一个明显的区别:
如果在一个ksh中设置了一些变量,然后调用了:
ksh `. ./myscript.ksh` 那么之前设置的变量可以在子脚本,即myscript.ksh中使用。
如果调用的是:
ksh `./myscript.ksh` 那么之前设置的变量不能在myscript.ksh中使用。
相关文章推荐
- 关于两种运行sh的方式: ./myscript.ksh and . ./myscript.ksh
- 【Android游戏开发之十】(优化处理)详细剖析Android Traceview 效率检视工具!分析程序运行速度!并讲解两种创建SDcard方式!
- 关于创建对象的两种方式
- 命令行运行jar包(idea+gradle)的两种方式
- 关于安卓中 WindowManager.LayoutParams()的两种方式
- Java并发编程初级篇(一):线程实现与运行的两种方式
- maven的两种可运行jar打包方式。1、内置依赖,2、外部依赖。
- 关于在C#中数组(byte[])复制的两种方式。字节偏移复制与安全复制
- (转)【Android游戏开发之十】(优化处理)详细剖析Android Traceview 效率检视工具!分析程序运行速度!并讲解两种创建SDcard方式!
- 关于Bitmap转byte数组的两种方式
- 懒汉式的安全优化方式,两种方式。线程同时运行的时候,不会创建两个对象
- Tuscany运行时两种方式
- VBS中运行应用程序的两种方式及WshShell对像浅析
- web项目嵌入Jetty运行的两种方式(Jetty插件和自制Jetty服务器)
- 关于使用lazytag线段树两种查询方式的比较研究
- Android中,关于service的启动两种方式描述不正确的是
- Maven运行TestNG的testcase 两种方式
- 关于串口通讯查询与中断两种方式
- 两种方式谁快谁慢——我的实践AND发现了与此无关的意外惊喜
- Lua实现类与继承的两种方式(复制)and (闭包)