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)来执 ...
随机推荐
- navicat从下载到使用
☆准备工作 确保电脑安装了mysql数据库 确定my.ini下的字符集设置为utf8 ☆下载navicat 输入网址 https://www.navicat.com 点击Downloads 点击Dow ...
- 每天php函数 - str_replace()
mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) 该函数返回一个字符 ...
- python 调用系统命令
Python执行系统命令一般的用到了四种方法, 第一种是 os.system(), 这个方法比较常用, 使用也简单, 会自动的生成一个进程,在进程完成后会自动退出, 需要注意的是 os.system ...
- #define与运算精度问题探究
#include <stdio.h> #define SQR(X) X*X int main(int argc, char* argv[]) { ; ; ; printf("SQ ...
- wordpress the_date 方法 偶尔为空的问题
估计很多人遇到这个问题: 一来是the_title(),the_permalink(),the_date()一路用下来,很正常也很正确 不爱读官方文档,因为文档中有个特别提示 文档:http://co ...
- svn local obstruction, incoming add upon merge
http://little418.com/2009/05/svn-local-obstruction-incoming-add-upon-merge.html If you've found this ...
- ubuntu timezone
change timezone sudo dpkg-reconfigure tzdata synchronize time sudo ntpdate time.windows.com
- mysql 存储过程 php版本
<?php /** * PHP操作Mysql存储过程示例 * * @author flyer0126 * @date 2011-12-23 * */ //配置数据库连接信息 $hostname ...
- SecureCRT登录Ubuntu 的中文乱码问题
(1)/var/lib/locales/supported.d/local文件中添加一行:zh_CN.UTF-8 UTF-8,执行sudo locale-gen下载文件 su - root (2) ...
- hitTest:WithEvent 和Responder Chain
这个方法是找到那个View被touch,当找到后就成为响应链的第一个了,如果他不能处理这个Event,那么就找nextResponder 直至application 如果不能处理,那就会丢弃掉. ht ...