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

📄 318.html

📁 著名的linux英雄站点的文档打包
💻 HTML
📖 第 1 页 / 共 2 页
字号:
          <TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 
        border=0></TD></TR></TBODY></TABLE>
      <TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff 
        border=0>
         <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
              
              <TR>
                <TD vAlign=top align=middle width="60%">
                  <TABLE cellSpacing=0 cellPadding=0 width="100%" 
                  background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
                    <TBODY>
                    <TR>
                        <TD vAlign=top width="80%"> 
                          <DIV align=center>
                        <FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
                            </FORM>
                        <TABLE cellSpacing=0 cellPadding=0 width="95%" 
                          border=0><TBODY>
                          <TR>
                            <TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif" 
                          height=30></TD></TR></TBODY></TABLE>
                        <TABLE cellSpacing=0 cellPadding=3 width="95%" 
                        align=center border=0>
                          <TBODY>
                          <TR>
                            <TD>
                              <TABLE cellSpacing=0 cellPadding=3 width="100%" 
                              border=0>
                                <TBODY>
                                <TR>
                                      <TD vAlign=top> 
<p><FONT class=normalfont><B><font color=blue>Bash中对变量的操作</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:作者<br>来自:Linux知识宝库<br>联系方式:无名<br><br>1.条件变量替换:<br>
 Bash Shell可以进行变量的条件替换,既只有某种条件发生时才进行替换,替换<br>
条件放在{}中.<br>
 (1) ${value:-word}<br>
     当变量未定义或者值为空时,返回值为word的内容,否则返回变量的值.<br>
 (2) ${value:=word}<br>
     与前者类似,只是若变量未定义或者值为空时,在返回word的值的同时将<br>
     word赋值给value<br>
 (3) ${value:?message}<br>
     若变量以赋值的话,正常替换.否则将消息message送到标准错误输出(若<br>
     此替换出现在Shell程序中,那么该程序将终止运行)<br>
 (4) ${value:+word}<br>
     若变量以赋值的话,其值才用word替换,否则不进行任何替换<br>
 (5) ${value:offset}<br>
     ${value:offset:length}<br>
     从变量中提取子串,这里offset和length可以是算术表达式.<br>
 (6) ${#value}<br>
     变量的字符个数 (变量的字符个数,并不是变量个数)<br>
 (7) ${value#pattern}<br>
     ${value##pattern}<br>
     去掉value中与pattern相匹配的部分,条件是value的开头与pattern相匹配<br>
     #与##的区别在于一个是最短匹配模式,一个是最长匹配模式.<br>
 (8) ${value%pattern}<br>
     ${value%%pattern}<br>
     于(7)类似,只是是从value的尾部于pattern相匹配,%与%%的区别与#与##一样<br>
 (9) ${value/pattern/string}<br>
     ${value//pattern/string}<br>
     进行变量内容的替换,把与pattern匹配的部分替换为string的内容,/与//的区<br>
     别与上同<br>
<br>
注意:上述条件变量替换中,除(2)外,其余均不影响变量本身的值<br>
<br>
2.变量的算术运算<br>
 在Bash Shell中,只能进行两个整数间的运算,其结果仍为整数.要进行算术<br>
运算,需要使用let命令,语法为:<br>
 let expr<br>
 expr是一个包含项和操作符的表达式,项可以是一个变量或是一个整数常数,<br>
当使用整数常数时,其默认为十进制整数,用户可以用radio#number来指定其它<br>
形式的整数,其中radio定义了整数是几进制表示的,number是该整数的值.若<br>
radio&gt;10,那么数字字符可从0-9和A-Z.<br>
 在表达式中支持的操作符及其含义为:<br>
 +,-,*,/,%     加,减,乘,除,取模<br>
 &gt;&gt;,&lt;&lt;,&,^,|   左移,右移,位与,位异或,位或<br>
 ?:            三元运算符.与C语言中的定义一致<br>
 ~             取补码<br>
 !,&gt;=,&lt;=,&gt;,&lt;,==,!=,&&,||<br>
 =,+=,-=,*=,/=,%=,&lt;&lt;=,&gt;&gt;=,&=,^=,|=<br>
 表达式式中也可以使用括号.括号或运算优先级的定义与一般计算机语言中的<br>
相同.<br>
 let命令具有返回值.当计算结果(若有多个表达式时,以最后一个为准)为0时,<br>
返回值为1,否则为0.<br>
 当表达式中含有shell的特殊字符(如|)时,需要用引用符('或")将其引用起来.<br>
 使用let时还需要注意的时,对于let x+y这样的式子,shell虽然计算了x+y的值<br>
但却将结果丢弃,若不想这样,可以使用let sum=x+y将x+y的结果保存在变量sum中<br>
 另外还可以使用((和))操作符取代let命令,而且这样的话,还可以省去对算术<br>
表达式的引用,如果想返回表达式的值,则需用$(())的格式.<br>
<br>
if的条件中,“=”用于比较字符串;“-eq”用于比较整型数。<br>
<br>
Bash内建参数<br>
===========<br>
<br>
PPID : 该bash的呼叫者process ID.  <br>
PWD : 目前的工作目录。  <br>
OLDPWD : 上一个工作目录。  <br>
REPLY : 当read命令没有参数时,直接设在REPLY上。  <br>
UID : User ID。  <br>
EUID : Effective User ID。  <br>
BASH : Bash的完整路径。  <br>
BASH_VERSION : Bash版本。  <br>
SHLVL : 每次有Bash执行时,数字加一。  <br>
RANDOM : 每次这个参数被用到时,就会产生一个乱数在RANDOM上。  <br>
SECONDS : 从这个Shell一开始启动後的时间。  <br>
LINENO : Script的行数。  <br>
HISTCMD : 历史记录数。  <br>
OPTARG : getopts处理的最後一个选项参数。  <br>
OPTIND : 下一个要由getopts所处理的参数号码。  <br>
HOSTTYPE : 机器种类。  <br>
OSTYPE : 作业系统名称。  <br>
IFS : Internal Field Separator。  <br>
PATH : 命令搜寻路径。  <br>
      PATH="/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:."  <br>
HOME : 目前使用者的home directory;  <br>
CDPATH : cd命令的搜寻路径。  <br>
ENV : 如果这个参数被设定,每次有shell script被执行时,将会执行它所设定的档名做为环境设定。  <br>
MAIL : 如果这个参数被设定,而且MAILPATH没有被设定,那麽有信件进来时,bash会通知使用者。  <br>
MAILCHECK : 设定多久时间检查邮件一次。  <br>
MAILPATH : 一串的邮件检查路径。  <br>
MAIL_WARNING : 如果有设定的话,邮件被读取後,将会显示讯息。  <br>
PS1 : 提示讯息设定,内定为"bash$ "。(请详见提示讯息一节。)  <br>
PS2 : 第二提示讯息设定,内定为"&gt; "。  <br>
PS3 : select命令所使用的提示讯息。  <br>
PS4 : 执行追踪时用的提示讯息设定,内定为"+ "。  <br>
HISTSIZE : 命令历史记录量,内定为500。  <br>
HISTFILE : 历史记录档,内定~/.bash_history。  <br>
HISTFILESIZE : 历史记录档行数最大值,内定500。  <br>
OPTERR : 如果设为1,bash会显示getopts的错误。  <br>
PROMPT_COMMAND : 如果设定的话,该值会在每次执行命令前都显示。  <br>
IGNOREEOF : 将EOF值当成输入,内定为10。  <br>
TMOUT : 如果设为大於零,该值被解译为输入等待秒数。若无输入,当成没有输入。  <br>
FCEDIT : fc命令的内定编辑器。  <br>
FIGNORE : 请详见READLINE。  <br>
INPUTRC : readline的startup file,内定~/.inputrc  <br>
notify : 如果设定了,bash立即报告被终结的背景程式。  <br>
history_control, HISTCONTROL : history使用。  <br>
command_oriented_history : 存入多行指令。  <br>
glob_dot_filenames : 如果设定了,bash将会把"."包含入档案路径中。  <br>
allow_null_glob_expansion : 如果设定了,bash允许路径明称为null string。  <br>
histchars : history使用。  <br>
nolinks : 如果设定了,执行指令时,不会跟随symbolic links。  <br>
hostname_completion_file, HOSTFILE : 包含与/etc/hosts相同格式的档名。  <br>
noclobber : 如果设定了,Bash不会覆写任何由"&gt;"、"&gt;&"及"&lt;&gt;"所操作的档案。  <br>
auto_resume : 请见任务控制一节。  <br>
no_exit_on_failed_exec : 如果该值存在,非互动的shell不会因为exec失败而跳出。  <br>
cdable_vars : 如果启动,而cd命令找不到目录,可切换到参数形态指定的目录下。<br>
</FONT><br>
                                      </TD>
                                    </TR>
                                <TR>
                                <TD colSpan=2><FONT 
                                class=middlefont></FONT><BR>
                                        <FONT 
                                class=normalfont>全文结束</FONT> </TD>
                                    </TR>
                                <TR>
                                <TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2 
                                height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
                        <TD vAlign=top width="20%" 
                      background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2> 
                          <DIV align=center> 
                            <table class=tableoutline cellspacing=1 cellpadding=4 
                        width="100%" align=center border=0>
                              <tr class=firstalt> 
                                <td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
                                <font class=normalfont><b>所有分类</b></font></td>
                              </tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td>    </tr>  </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td>    </tr>  </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%>   <table width=100% border=0>    <tr>       <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td>    </tr>  </table></td></tr>                            </table>
                          </DIV></TD></TR>
                    <TR vAlign=top>
                        <TD width="80%"> 
                          <DIV align=center><BR>
                          </DIV>
                        </TD></TR></TBODY></TABLE></TD></TR>
                </TABLE></TD></TR>
          </TABLE>
      <TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee 
        border=0><TBODY>
        <TR>
          <TD width="50%">
              <P><FONT class=middlefont>版权所有 &copy; 2004 <A 
            href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
                违者必究. </FONT></P>
            </TD>
          <TD width="50%">
              <DIV align=right><FONT class=middlefont>Powered by: <A 
            href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
            </TD></TR></TBODY></TABLE>
      <CENTER></CENTER></TD></TR>
    </TABLE></CENTER></BODY></HTML>

⌨️ 快捷键说明

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