<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>阿德日志 &#187; export</title>
	<atom:link href="http://blog.delai.me/tag/export/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.delai.me</link>
	<description>我的自留地</description>
	<lastBuildDate>Thu, 29 Dec 2011 03:33:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Shell中的export &amp; sh &amp; source</title>
		<link>http://blog.delai.me/2008/10/export-sh-source.html</link>
		<comments>http://blog.delai.me/2008/10/export-sh-source.html#comments</comments>
		<pubDate>Mon, 27 Oct 2008 15:31:45 +0000</pubDate>
		<dc:creator>阿德</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[Linux/GNU]]></category>
		<category><![CDATA[sh]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[总结]]></category>

		<guid isPermaLink="false">http://www.soulward.cn/?p=509</guid>
		<description><![CDATA[今天做了几个实验总算把export+变量的用法给弄清楚了，过程不说，留下结果以备忘：

1. 在一个shell中（脚本）执行export+变量 的作用就是把该变量变成其父shell的变量，当执行该语句的shell或... ]]></description>
			<content:encoded><![CDATA[<p>今天做了几个实验总算把export+变量的用法给弄清楚了，过程不说，留下结果以备忘：</p>
<p>1. 当进程创建一个字进程时候，父进程并不会将普通变量的值传递给它的子进程。</p>
<p>而export就是解决这个问题用的。在父进程中export A 后，在子进程中就可以使用变量A了。</p>
<p>2. sh+脚本：重新建立一个子shell执行脚本里面的语句，该子shell继承父shell的变量，但子shell新建的、改变的变量不会被带回父shell，除非使用export。</p>
<p>可以这么理解：打开一个终端程序 = sh = 执行bash命令</p>
<p>3. source+脚本：这个命令其实只是简单地读取脚本里面的语句依次在当前shell里面执行，没有建立新的子shell。那么脚本里面所有新建、改变变量的语句都会保存在当前shell里面。</p>
<p>所以，假设one.sh里面的内容是：export test=123 ；two.sh里面的内容是：test=123 。</p>
<p>那么，sh ./one.sh 在效果上等同于 source two.sh</p>
<hr /><h2>Related posts:</h2><ul><li><a href="http://blog.delai.me/2009/03/virginity-rates.html" rel="bookmark" title="Permanent Link: Wellesley College各专业处女比例之调查">Wellesley College各专业处女比例之调查</a></li></ul><hr /><strong>[原文链接：<a href="http://blog.delai.me/2008/10/export-sh-source.html">http://blog.delai.me/2008/10/export-sh-source.html</a>] </strong>]]></content:encoded>
			<wfw:commentRss>http://blog.delai.me/2008/10/export-sh-source.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

