【总结】关于shell执行,export 和 source
来源:互联网 发布:淘宝网络兼职 编辑:程序博客网 时间:2024/06/08 07:15
1、执行脚本时是在一个子shell环境运行的,脚本执行完后该子shell自动退出
[acefei@localhost : ~/shell] ^_^$cat 1.sh#!/bin/bashecho "In 1.sh : Invoking 2.sh"./2.shecho "In 1.sh : now path is `pwd`"echo "In 1.sh : exit"[acefei@localhost : ~/shell] ^_^$cat 2.sh#!/bin/bashcd /tmpecho "In 2.sh : now path is `pwd`"echo "In 2.sh : exit"[acefei@localhost : ~/shell] ^_^$./1.shIn 1.sh : Invoking 2.shIn 2.sh : now path is /tmpIn 2.sh : exitIn 1.sh : now path is /home/acefei/shellIn 1.sh : exit
2、一个shell中的系统环境变量才会被复制到子shell中(用export定义的变量)
[acefei@localhost : ~/shell] ^_^$cat 1.sh#!/bin/bashecho "In 1.sh : export a = 123"export a=123echo "In 1.sh : Invoking 2.sh"./2.shecho "In 1.sh : exit"[acefei@localhost : ~/shell] ^_^$cat 2.sh#!/bin/bashecho "In 2.sh : a = $a"echo "In 2.sh : exit"[acefei@localhost : ~/shell] ^_^$./1.shIn 1.sh : export a = 123In 1.sh : Invoking 2.shIn 2.sh : a = 123In 2.sh : exitIn 1.sh : exit
3、一个shell中的系统环境变量只对该shell或者它的子shell有效,该shell结束时变量消失(并不能返回到父shell中)
[acefei@localhost : ~/shell] ^_^$cat 2.sh#!/bin/bashecho "In 2.sh : Invoking 1.sh"./1.shecho "In 2.sh : a = $a"echo "In 2.sh : exit"[acefei@localhost : ~/shell] ^_^$cat 1.sh#!/bin/bashecho "In 1.sh : export a = 123"export a=123echo "In 1.sh : exit"[acefei@localhost : ~/shell] ^_^$./2.shIn 2.sh : Invoking 1.shIn 1.sh : export a = 123In 1.sh : exitIn 2.sh : a =In 2.sh : exit
4、不用export定义的变量只对该shell有效,对子shell也是无效的
Read and execute commands from filename in the current shell environment and return the exit status of the last command executed from filename.
直接执行一个脚本文件是在一个子shell中运行的,而source则是在当前shell环境中运行的。
[acefei@localhost : ~/shell] ^_^$cat 1.sh#!/bin/bashecho "In 1.sh : define a = 123"a=123echo "In 1.sh : exit"[acefei@localhost : ~/shell] ^_^$cat 2.sh#!/bin/bashecho "In 2.sh : source 1.sh"#./1.shsource ./1.shecho "In 2.sh : a = $a"echo "In 2.sh : exit"[acefei@localhost : ~/shell] ^_^$./2.shIn 2.sh : source 1.shIn 1.sh : define a = 123In 1.sh : exitIn 2.sh : a = 123In 2.sh : exit
- 【总结】关于shell执行,export 和 source
- 学习笔记:shell 中的 [export] 和 [source]
- shell编程三source和export
- shell中source和export区别
- Shell环境和变量生存期-export和source
- shell中source与export
- shell脚本的执行和source
- linux source和export命令
- linux 中source和export
- 关于linux的export命令和shell变量的生命周期
- linux export的作用和source命令
- Linux-source和export命令小结
- [Linux]A Shell to Export Source From SVN
- export ,source 理解shell变量的生存周期
- how shell env change when export or source
- export与source 一个shell脚本文件的关系
- shell中的fork、source和exec总结(包括环境变量)
- shell中的fork、source和exec总结(包括环境变量)
- 每日学习笔记(20)
- Oracle Merge Into 的用法详解实例
- Oracle 物化视图
- Android 多点触摸
- Jar 转 EXE 可以脱离 java 环境 jar to exe和Jsmooth 的使用
- 【总结】关于shell执行,export 和 source
- jQuery实现多选下来框(multiple select)
- 程序员面试题精选100题(10)-在排序数组中查找和为给定值的两个数字
- div 实现长英文字母自动换行CSS
- Oracle 高水位(HWM: High Water Mark) 说明
- 短信平台开发之短信猫资料简介
- android中SurfaceView SurfaceHolder SurfaceHolder.Callback 关系 理解
- cPanel面板中文件夹的结构说明
- C# 文件操作(上传 下载 删除 文件列表)