`
kanwoerzi
  • 浏览: 1645360 次
文章分类
社区版块
存档分类
最新评论

source命令

 
阅读更多
source命令<wbr style="line-height:25px">:<br style="line-height:25px"><span style="color:#ff00ff; line-height:25px">source命令</span>也称为“<wbr style="line-height:25px"><span style="color:#ff6600; line-height:25px">点命令</span><wbr style="line-height:25px">”,也就是一个点符号(.)。source命令通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录。<br style="line-height:25px"> source可以强行让一个脚本去影响当前的环境(他执行该脚本中的全部命令,而不关脚本文件的权限如何设置).<br style="line-height:25px"> source命令(从CShell而来)是bashshell的内置命令。点命令,就是一个点符号,(从BourneShell而来)是source的另一名称。<br style="line-height:25px"> 同样的,当前脚本中设置的变量也将作为脚本的环境,source(或点)命令通常用于重新执行刚修改的初始化文件,如.bash_profile和.profile等等。例如,如果在登录后对.bash_profile中的EDITER和TERM变量做了修改,则可以用source命令重新执行.bash_profile中的命令而不用注销并重新登录。<br style="line-height:25px"> 把两个命令用&amp;&amp;联接起来,如makemrproper&amp;&amp;makemenuconfig,表示要第一个命令执行成功才能执行第二个命令。<br style="line-height:25px"> 注意:source可以让脚本影响它们的父shell环境,这和export去影响子shell环境相反。<br style="line-height:25px"> 用法:<br style="line-height:25px"> sourcefilename或.filename<br style="line-height:25px"> source命令除了上述的用途之外,还有一个另外一个用途。在对编译系统核心时常常需要输入一长串的命令,如:<br style="line-height:25px"><span style="color:#3366ff; line-height:25px">makemrproper<br style="line-height:25px"> makemenuconfig<br style="line-height:25px"> makedep<br style="line-height:25px"> makeclean<br style="line-height:25px"> makebzImage</span><br style="line-height:25px"> ………<br style="line-height:25px"> 如果把这些命令做成一个文件,让它自动顺序执行,对于需要多次反复编译系统核心的用户来说会很方便,<br style="line-height:25px"> 而用source命令就可以做到这一点,它的作用就是把一个文件的内容当成shell来执行,<br style="line-height:25px"> 先在linux的源代码目录下(如/usr/src/linux-2.4.20)建立一个文件,如make_command,在其中输入一下内容:<br style="line-height:25px"><span style="color:#3366ff; line-height:25px">makemrproper&amp;&amp;<br style="line-height:25px"> makemenuconfig&amp;&amp;<br style="line-height:25px"> makedep&amp;&amp;<br style="line-height:25px"> makeclean&amp;&amp;<br style="line-height:25px"> makebzImage&amp;&amp;<br style="line-height:25px"> makemodules&amp;&amp;<br style="line-height:25px"> makemodules_install&amp;&amp;<br style="line-height:25px"> cparch/i386/boot/bzImage/boot/vmlinuz_new&amp;&amp;<br style="line-height:25px"> cpSystem.map/boot&amp;&amp;<br style="line-height:25px"> vi/etc/lilo.conf&amp;&amp;<br style="line-height:25px"> lilo-v</span><br style="line-height:25px"> 文件建立好之后,每次编译核心的时候,只需要在/usr/src/linux-2.4.20下输入:<br style="line-height:25px"><span style="color:#0000ff; line-height:25px">sourcemake_command</span><br style="line-height:25px"> 即可,如果你用的不是lilo来引导系统,可以把最后两行去掉,配置自己的引导程序来引导内核。<br style="line-height:25px"> 顺便补充一点,&amp;&amp;命令表示顺序执行由它连接的命令,但是只有它之前的命令成功执行完成了之后才可以继续执行它后面的命令。<br style="line-height:25px"> 注意1:<span style="color:#339966; line-height:25px">source.bash_rc</span><span style="color:#000080; line-height:25px">与</span><span style="color:#008000; line-height:25px">..bash_rc</span><span style="color:#000080; line-height:25px">是等效的。</span><br style="line-height:25px"> 注意2:<br style="line-height:25px"><span style="line-height:25px"><wbr style="line-height:25px">source命令与shellscripts的区别</wbr></span><wbr style="line-height:25px">,<br style="line-height:25px"> source在当前bash环境下执行命令,而scripts是启动一个子shell来执行命令。<br style="line-height:25px"> 这样如果把设置环境变量(或alias等等)的命令写进scripts中,就只会影响子shell,无法改变当前的BASH,<br style="line-height:25px"> 所以通过文件(命令列)设置环境变量时,要用source命令。<br style="line-height:25px"> 注意3:通过sh命令执行的文件里面不能再执行source命令,系统会无法识别。也就是说有source命令的文件不能用sh命令在执行。这个感觉有点傻。</wbr></wbr></wbr></wbr>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics