shell各种执行方式区别
shell 脚本各种执行方式(source ./*.sh, . ./*.sh, ./*.sh)的区别
原文出处:http://blog.csdn.net/dance_rise/article/details/8573560
结论一: ./*.sh的执行方式等价于sh ./*.sh或者bash ./*.sh,此三种执行脚本的方式都是重新启动一个子shell,在子shell中执行此脚本(通过fork实现)。
结论二: .source ./*.sh和 . ./*.sh的执行方式是等价的,即两种执行方式都是在当前shell进程中执行此脚本,而不是重新启动一个shell 而在子shell进程中执行此脚本。
验证依据:没有被export导出的变量(即非环境变量)是不能被子shell继承的
验证结果:
[root@localhost ~]#name=dangxu //定义一般变量
[root@localhost ~]# echo ${name}
dangxu
[root@localhost ~]# cat test.sh //验证脚本,实例化标题中的./*.sh
#!/bin/sh
echo ${name}
[root@localhost ~]# ls -l test.sh //验证脚本可执行
-rwxr-xr-x 1 root root 23 Feb 6 11:09 test.sh
[root@localhost ~]# ./test.sh //以下三个命令证明了结论一
[root@localhost ~]# sh ./test.sh
[root@localhost ~]# bash ./test.sh
[root@localhost ~]# . ./test.sh //以下两个命令证明了结论二
dangxu
[root@localhost ~]# source ./test.sh
dangxu
shell各种执行方式区别的更多相关文章
- 『SHELL』--SHELL脚本执行方式(转)
Shell脚本的执行方式: 注明:wd代表“脚本保存的目录” 1.fork 语法:/wd/shell.sh fork是最普通的, 就是直接在脚本里面用/wd/shell.sh来调用shell.sh这个 ...
- linux shell的执行方式
./ ping.sh 这个意思 ,'./'的意思是在当前目录执行, ping.sh----------------------------------------------------------- ...
- shell脚本执行方式
# BY THE WAY, 其实这块内容算是比较简单的,但是都比较常记得它最基本的两种方式,另外两种却忘记了 1. 利用sh或bash命令执行 sh test.sh bash test.sh 2. 在 ...
- shell-1.shell概述、2.shell脚本执行方式
目录
- Linux - Shell - shell 执行方式
概述 shell 的执行方式 背景 偶尔执行个 shell 脚本 一般都用 './script' 执行 最近忽然看到 有不同的执行方式, 感觉有必要整理一下, 然后和大家分享 准备 os centos ...
- 转:linux执行shell脚本的方式及一些区别
假设shell脚本文件为hello.sh放在/root目录下.下面介绍几种在终端执行shell脚本的方法: [root@localhost home]# cd /root/ [root@localho ...
- shell script 执行常用的两种方式
2016-11-17 直接输入脚本名执行 ./script #!/bin/bash# /root/shell/001 # 2016-11-17 test for script running name ...
- shell入门笔记1:执行方式、运行方式、变量、替换
说明: 本文是关于http://c.biancheng.net/cpp/shell/的相关笔记 shell的两种执行方式 交互式(interactive) 解释执行用户的命令,用户输入一条命令,She ...
- Shell脚本的三种执行方式
Shell脚本的执行方式可以有以下几种: 方式一: ./script.sh # 利用小数点来执行 方式二: sh script.sh 或 bash script.sh # 利用bash(sh)来执 ...
随机推荐
- 一些用过的C#类库收集
[System.Math] [System.Guid] [System.Management.Automation.RuntimeException] [System.DateTime] [Syste ...
- Objective-C、C++和swift 的运行效率比较
自己做iOS开发,以后慢慢都要转swift,前段时间看到网上的一个帖子,说swift的运行效率奇低,觉得自己有必要验证一下. 我用了一个最简单的加法运算,从0加到10000000,看三种语言的时耗. ...
- sqlite相关工具使用
sqlite3可视化工具 1.sudo apt-get install sqlitebrowser 2.sudo apt-get install sqliteman3.sqlitestudio需要去官 ...
- mongodb 3.0 版本分片部署步骤
# linux 网络优化 1. 文件中/etc/sysctl.conf, 加入 net.core.somaxconn = 2048 fs.file-max = 2000000 fs.nr_open = ...
- 2016.05.04,英语,《Vocabulary Builder》Unit 22
acerb/acri: comes from the Latin adjective acer, meaning 'sharp' or 'sour'. acerbic: [ə'sɜːrbɪk] adj ...
- AMD GPU spec (public)
http://www.x.org/docs/AMD/old/ Index of /docs/AMD/old Name Last modified Size Description Parent Dir ...
- laravel url() 和 asset() 的区别
asset()方法用于引入 CSS/JavaScript/images 等文件,文件必须存放在public文件目录下.url()方法生成一个完整的网址.
- mysql null值的特殊处理
实例 尝试以下实例: root@host# mysql -u root -p password; Enter password:******* mysql> use RUNOOB; Databa ...
- spring对dao层的支持(datasource的作用)
本文大多数内容转自“http://www.cnblogs.com/liunanjava/p/4412408.html”感谢原作者 在做一个项目时,持久层并没有使用spring jpa和hibernat ...
- Ubuntu 安装字体
将字体Copy到/usr/share/fonts/windows目录下,然后执行以下几条命令更新系统字体缓存: cd /usr/share/fonts/vista/ sudo mkfontscale ...