推出具有./script.sh和脚本之间的区别。 ./script.sh [英] Difference between launching a script with ./script.sh and . ./script.sh

查看:247
本文介绍了推出具有./script.sh和脚本之间的区别。 ./script.sh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我是用启动脚本之间的bash shell中的区别
./ script.sh 。 ./script.sh

Please tell me what is the difference in bash shell between launching a script with ./script.sh and . ./script.sh?

推荐答案

klausbyskov 说,第一种形式requries该文件有其可执行权限位设置。

As klausbyskov says, the first form requries that the file have its executable permission bit set.

但更重要的是,第一种形式执行在单独的进程脚本(来自不同的,独立的,并且无法在启动它的壳的变化)。第二种形式使得初始外壳直接运行该文件中的命令(如如果你有他们键入到外壳,或者,如果他们被列入,做了采购脚本)。

But more importantly, the first form executes the script in a separate process (distinct from, independent of, and unable to make changes in the shell that launched it). The second form causes the initial shell to directly run the commands from the file (as if you had typed them into the shell, or as if they were included in the script that does the ‘sourcing’).

包含 FOO =栏的脚本;出口FOO 将不能创建在运行的第一个变种壳体中的出口 FOO 环境变量,但它会在shell创建这样一个变量运行该第二变型

A script that contains FOO=bar; export FOO will have not create an exported FOO environment variable in the shell that runs the first variant, but it will create such a variable in a shell that runs the second variant.

第二种形式('采购')是一个有点像的#include 用C

The second form (‘sourcing’) is a bit like a #include in C.

这篇关于推出具有./script.sh和脚本之间的区别。 ./script.sh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆