⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 详解bash命令行处理 linuxsir_org.htm

📁 linuxSir 网站的精华文章
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0040)http://www.linuxsir.org/main/?q=node/134 -->
<HTML lang=zh-hans xml:lang="zh-hans" 
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>详解Bash命令行处理 | LinuxSir.Org</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE type=text/css media=all>@import url( misc/drupal.css );
</STYLE>

<STYLE type=text/css>@import url( http://www.linuxsir.org/main/modules/codefilter/codefilter.css );
</STYLE>

<STYLE type=text/css media=all>@import url( modules/taxonomy_context/taxonomy_context.css );
</STYLE>
<LINK media=screen href="详解Bash命令行处理  LinuxSir_Org.files/menuExpandable3.css" 
type=text/css rel=stylesheet>
<SCRIPT src="详解Bash命令行处理  LinuxSir_Org.files/menuExpandable3.js" 
type=text/javascript></SCRIPT>
<LINK href="详解Bash命令行处理  LinuxSir_Org.files/common.css" type=text/css 
rel=stylesheet>
<STYLE type=text/css media=all>@import url( themes/chameleon/marvin/style.css );
</STYLE>

<META content="MSHTML 6.00.2900.2912" name=GENERATOR></HEAD>
<BODY>
<DIV id=header><A title=Home href="http://www.linuxsir.org/main/"><IMG alt=Home 
src="详解Bash命令行处理  LinuxSir_Org.files/logo.jpg"></A></DIV>
<DIV class=navlinks>
<DIV class=primary><A href="http://www.linuxsir.org/main/?q"><FONT 
color=white>首页</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/34"><FONT 
color=white>事件</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/1/25/"><FONT 
color=white>文档</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/35/48/"><FONT 
color=white>资源</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=search"><FONT color=white>搜索</FONT></A> | 
<A href="http://www.linuxsir.org/bbs"><FONT color=white>论坛</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=taxonomy/term/38"><FONT 
color=white>贡献者</FONT></A> | <A 
href="http://www.linuxsir.org/main/?q=node/3"><FONT color=white>关于</FONT></A> | 
<A href="http://www.linuxsir.org/main/?q=user"><FONT 
color=white>注册/登录</FONT></A></DIV></DIV>
<TABLE id=content>
  <TBODY>
  <TR>
    <TD id=sidebar-left>
      <DIV class="block block-block" id=block-block-1>
      <H2 class=title>子站索引</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://fedora.linuxsir.org/" target?_blank?>Fedora中文</A> 
        <LI><A href="http://debian.linuxsir.org/" target?_blank?>Debian中文</A> 
        <LI><A href="http://lfs.linuxsir.org/" target?_blank?>LFS 中文</A> 
        <LI><A href="http://slack.linuxsir.org/">Slackware</A> 
        <LI><A href="http://gentoo.linuxsir.org/">Gentoo中文</A> 
        <LI><A href="http://arch.linuxsir.org/">Arch 中文</A> </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-3>
      <H2 class=title>重要资讯</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/36">本站公告</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/34">新闻事件</A> 
        <LI><A href="http://www.linuxsir.org/bbs" target=_blank>本站论坛</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/38">贡 献 者</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-7>
      <H2 class=title>项目索引</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.fcitx.org/" target=_blank>小企鹅输入法</A> 
        <LI><A href="http://lumaqq.linuxsir.org/" target=_blank>LumaQQ</A> 
        <LI><A href="http://openq.linuxsir.org/" target=_blank>OpenQ</A> 
        <LI><A href="http://www.relaxbsd.org/" target=_blank>RelaxBSD</A> 
      </LI></UL></DIV></DIV>
      <DIV class="block block-user" id=block-user-1>
      <H2 class=title>站点导航</H2>
      <DIV class=content>
      <DIV class=menu>
      <UL>
        <LI class=leaf><A title=注册/登录 
        href="http://www.linuxsir.org/main/?q=user">注册/登录</A> 
        <LI class=collapsed><A 
        href="http://www.linuxsir.org/main/?q=aggregator">新闻聚合</A> 
      </LI></UL></DIV></DIV></DIV>
      <DIV class="block block-aggregator" id=block-aggregator-feed-2>
      <H2 class=title>LinuxSir.Org 论坛</H2>
      <DIV class=content>
      <DIV class=item-list>
      <UL>
        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=272173&amp;goto=newpost">[PKGBUILD] 
        reciteword -- 轻轻松松背单词</A> 
        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=272172&amp;goto=newpost">小企鹅输入法能否使用郑码?</A> 

        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=272171&amp;goto=newpost">一个可能的bug</A> 

        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=272170&amp;goto=newpost">保留隐藏分区,同时装win和linux?</A> 

        <LI><A 
        href="http://www.linuxsir.org/bbs/showthread.php?t=272169&amp;goto=newpost">请教:suse10.1下vmware安装的winxp如何共享linux 
        mnt目录下挂载的fat32分区</A> </LI></UL></DIV>
      <DIV class=more-link><A title=查看此feed的最新消息 
      href="http://www.linuxsir.org/main/?q=aggregator/sources/2">更多</A></DIV></DIV></DIV>
      <DIV class="block block-user" id=block-user-2>
      <H2 class=title>最新注册</H2>
      <DIV class=content>
      <DIV class=item-list>
      <UL>
        <LI>hzhpipi
        <LI>xigua2005
        <LI>ghost
        <LI>Carrie0225
        <LI>Sirius</LI></UL></DIV></DIV></DIV>
      <DIV class="block block-user" id=block-user-3>
      <H2 class=title>当前在线</H2>
      <DIV class=content>1 用户 和 57 游客 在线
      <DIV class=item-list>
      <H3>在线用户</H3>
      <UL>
        <LI>hzhpipi</LI></UL></DIV></DIV></DIV></TD>
    <TD id=main>
      <DIV class=breadcrumb><A href="http://www.linuxsir.org/main/?q=">首页</A> » 
      <A href="http://www.linuxsir.org/main/?q=taxonomy/term/1">Linux</A></DIV>
      <H2>详解Bash命令行处理</H2><!-- begin content -->
      <DIV class=node>
      <DIV class=content>
      <P><B>作者:</B><A 
      href="http://www.linuxsir.org/bbs/member.php?u=11233">home_king</A><BR><B>来自:</B>LinuxSir.Org<BR><B>整理:</B>北南南北<BR><B>摘要:</B>我看很多兄弟写脚本或命令时出现错误的主要原因,是因为不了解bash的命令行处理。我在这里总结了一下,大家可以参考一下。其中也涉及到双引号,单引号以及eval的技巧,我会一一讲述。</P>
      <P><FONT size=4><B>目录</B></FONT></P>
      <P><A 
      href="http://www.linuxsir.org/main/?q=node/134#0"><B>前言</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/134#1"><B>一、bash命令处理的12个步骤;</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/134#2"><B>二、关于引用</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/134#3"><B>三、eval的作用;</B></A></P>
      <UL><A 
        href="http://www.linuxsir.org/main/?q=node/134#3.1">1、例子1:用eval技巧实现shell的控制结构for</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/134#3.2">2、例子2:一个典型错误的例子</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/134#3.3">3、例子3:设置系统的ls色彩显示</A> 
      </UL>
      <P><A 
      href="http://www.linuxsir.org/main/?q=node/134#4"><B>四、命令优先级表</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/134#5"><B>五、鉴于一些学习中会遇到的困惑,我再给出一些有趣的命令</B></A></P>
      <UL><A href="http://www.linuxsir.org/main/?q=node/134#5.1">1、command 
        builtin enable</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/134#5.2">2、command</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/134#5.3">3、builtin</A><BR><A 
        href="http://www.linuxsir.org/main/?q=node/134#5.4">4、enable</A> </UL>
      <P><A 
      href="http://www.linuxsir.org/main/?q=node/134#6"><B>六、关于本文</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/134#7"><B>七、相关文档</B></A></P>
      <P><FONT 
      color=blue><B><BR>++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>正文<BR>++++++++++++++++++++++++++++++++++++++++++++++++++++<BR></B></FONT></P>
      <P><FONT id=0 size=4><B><BR>前言<BR></B></FONT></P>
      <P>我看很多兄弟写脚本或命令时出现错误的主要原因,是因为不了解bash的命令行处理。我在这里总结了一下,大家可以参考一下。其中也涉及到双引号,单引号以及eval的技巧,我会一一讲述。</P>
      <P>Shell从标准输入或脚本中读取的每行称为一个管道行,它包含一个或多个由0个或多个管道字符(|)分隔的命令。对每一个管道行,进行12个步骤的处理。<BR><FONT 
      size=4><B><BR>一、bash命令处理的12个步骤;<BR></B></FONT></P><PRE>                               +-------------+           单引号
    |-------------------------&gt;|             |--------------------------|
    |  -----------------------&gt;| 1.分隔成记号|---- ---------------|     |
    |  |   -------------------&gt;|             |      双引号        |     |
    |  |   |                   +-------------+                    |     |
    |  |   |                          ||                          |     |
    |  |   |读取下一个命令            \/                          |     |
    |  |   |     +-------------------------------------------+    |     |
    |  |   |     |                    2.                     |    |     |
    |  |   ------|              检验第一个记号               |    |     |
    |  |         |开放的关键字                    其他关键字 |    |     |
    |  |         |               非关键字                    |    |     |
    |  |         +-------------------------------------------+    |     |
    |  |                              ||                          |     |
    |  |                              \/                          |     |
    |  |            +-----------------------------+               |     |
    |  |  扩展别名  |           3. 检验第一个记号 |               |     |
    |  |------------|  别名                       |               |     |
    |               |              不是别名       |               |     |
    |               +-----------------------------+               |     |
    |                                 ||                          |     |
    |                                 \/                          |     |
    |                           +--------------+                  |     |
    |                           | 4.大括号扩展 |                  |     |
    |                           +--------------+                  |     |
    |                                 ||                          |     |
    |                                 \/                          |     |
    |                           +--------------+                  |     |
    |                           | 5.~符号扩展  |                  |     |
    |                           +--------------+                  |     |
    |                                 ||                          |     |
    |                                 \/                          |     |
    |                           +--------------+       双引号     |     |
    |                           |  6.参数扩展  |&lt;-----------------|     |
    |                           +--------------+                        |
    |                                 ||                                |
    |                                 \/                                |
    |                    +------------------------------+               |
    |                    |  7.命令替换(嵌套命令行处理)  |               |
    |                    +------------------------------+               |
    |                                 ||                                |
    |                                 \/                                |
    |                           +--------------+      双引号            |
    |                           |  8.算术扩展  |------------------|     |
    |                           +--------------+                  |     |

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -