test

<!DOCTYPE html> javascript

<html><head> css

<meta http-equiv="Content-Type" content="text/html; charset=unicode"> html

<!--defaultCSS--> java

<title>_1_1bash變量_交互_邏輯.md</title> node






<style type="text/css" id="wiz_todo_style_id" wiz_link_version="01.00.09">.wiz-todo, .wiz-todo-img {width: 16px; height: 16px; cursor: default; padding: 0 10px 0 2px; vertical-align: -10%;-webkit-user-select: none;} .wiz-todo-label { display: inline-block; padding-top: 7px; padding-bottom: 6px; line-height: 1.5;} .wiz-todo-label-checked {  color: #666;} .wiz-todo-label-unchecked {text-decoration: initial;} .wiz-todo-completed-info {padding-left: 44px; display: inline-block; } .wiz-todo-avatar { width:20px; height: 20px; vertical-align: -20%; margin-right:10px; border-radius: 2px;} .wiz-todo-account, .wiz-todo-dt { color: #666; }</style> web
















<style id="wiz_custom_css">        html, body {            font-size: 15px;        }        body {            font-family: Helvetica, 'Hiragino Sans GB', '微軟雅黑', 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;            line-height: 1.6;            margin: 0;            padding: 20px 36px;            padding: 1.33rem 2.4rem;        }        h1, h2, h3, h4, h5, h6 {            margin: 20px 0 10px;            margin: 1.33rem 0 0.667rem;            padding: 0;            font-weight: bold;        }        h1 {            font-size: 21px;            font-size: 1.4rem;        }        h2 {            font-size: 20px;            font-size: 1.33rem;        }        h3 {            font-size: 18px;            font-size: 1.2rem;        }        h4 {            font-size: 17px;            font-size: 1.13rem;        }        h5 {            font-size: 15px;            font-size: 1rem;        }        h6 {            font-size: 15px;            font-size: 1rem;            color: #777777;            margin: 1rem 0;        }        div, p, ul, ol, dl, li {            margin: 0;        }        blockquote, table, pre, code {            margin: 8px 0;        }        ul, ol {            padding-left: 32px;            padding-left: 2.13rem;        }        blockquote {            padding: 0 12px;            padding: 0 0.8rem;        }        blockquote > :first-child {            margin-top: 0;        }        blockquote > :last-child {            margin-bottom: 0;        }        img {            border: 0;            max-width: 100%;            height: auto !important;            margin: 2px 0;        }        table {            border-collapse: collapse;            border: 1px solid #bbbbbb;        }        td {            padding: 4px 8px;            border-collapse: collapse;            border: 1px solid #bbbbbb;        }        @media screen and (max-width: 660px) {            body {                padding: 20px 18px;                padding: 1.33rem 1.2rem;            }        }        @media only screen and (-webkit-max-device-width: 1024px), only screen and (-o-max-device-width: 1024px), only screen and (max-device-width: 1024px), only screen and (-webkit-min-device-pixel-ratio: 3), only screen and (-o-min-device-pixel-ratio: 3), only screen and (min-device-pixel-ratio: 3) {            html, body {                font-size: 17px;            }            body {                line-height: 1.7;                padding: 0.75rem 0.9375rem;                color: #353c47;            }            h1 {                font-size: 2.125rem;            }            h2 {                font-size: 1.875rem;            }            h3 {                font-size: 1.625rem;            }            h4 {                font-size: 1.375rem;            }            h5 {                font-size: 1.125rem;            }            h6 {                color: inherit;            }            ul, ol {                padding-left: 2.5rem;            }            blockquote {                padding: 0 0.9375rem;            }        }</style><style name="wiz_tmp_editor_style">html, body {    font-size: 15px;}body {    font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;    line-height: 1.6;    color: ;    background-color: ;    margin: 0;    padding: 16px 20px;}h1, h2, h3, h4, h5, h6 {    margin: 20px 0 10px;    margin: 1.33rem 0 0.667rem;    padding: 0;    font-weight: bold;}h1 {    font-size: 21px;    font-size: 1.4rem;}h2 {    font-size: 20px;    font-size: 1.33rem;}h3 {    font-size: 18px;    font-size: 1.2rem;}h4 {    font-size: 17px;    font-size: 1.13rem;}h5 {    font-size: 15px;    font-size: 1rem;}h6 {    font-size: 15px;    font-size: 1rem;    color: #777777;    margin: 1rem 0;}div, p, ul, ol, dl, li {    margin: 0;}blockquote, table, pre, code{    margin: 8px 0;}ul, ol {    padding-left: 32px;    padding-left: 2.13rem;}blockquote {    border-left: 4px solid #dddddd;    padding: 0 12px;    padding: 0 0.8rem;}blockquote > :first-child {    margin-top: 0;}blockquote > :last-child {    margin-bottom: 0;}img {    border: 0;    max-width: 100%;    height: auto !important;    margin: 2px 0;}table {    border-collapse: collapse;    border: 1px solid #bbbbbb;}td {    padding:4px 8px;    border-collapse: collapse;    border: 1px solid #bbbbbb;}@media screen and (max-width: 660px) {    body {        padding: 20px 18px;        padding: 1.33rem 1.2rem;    }}@media only screen and (-webkit-max-device-width: 1024px), only screen and (-o-max-device-width: 1024px), only screen and (max-device-width: 1024px), only screen and (-webkit-min-device-pixel-ratio: 3), only screen and (-o-min-device-pixel-ratio: 3), only screen and (min-device-pixel-ratio: 3) {    html, body {        font-size: 17px;    }    body {        line-height: 1.7;        padding: 0.75rem 0.9375rem;        color: #353c47;    }    h1 {        font-size: 2.125rem;    }    h2 {        font-size: 1.875rem;    }    h3 {        font-size: 1.625rem;    }    h4 {        font-size: 1.375rem;    }    h5 {        font-size: 1.125rem;    }    h6 {        color: inherit;    }    ul, ol {        padding-left: 2.5rem;    }    blockquote {        padding: 0 0.9375rem;    }}</style><link rel="stylesheet" type="text/css" href="file:///F:\Program Files (x86)\WizNote\WizTools\htmleditor\editor.css" wiz_style="unsave" charset="utf-8"><link rel="stylesheet" type="text/css" href="file:///F:\Program Files (x86)\WizNote\WizTools\htmleditor\scrollbar.css" wiz_style="unsave" charset="utf-8"><script type="text/javascript" src="file:///F:\Program Files (x86)\WizNote\WizTools\htmleditor\utils.js" wiz_style="unsave" charset="utf-8"></script><script type="text/javascript" src="file:///F:\Program Files (x86)\WizNote\WizTools\htmleditor\localize.js" wiz_style="unsave" charset="utf-8"></script><script type="text/javascript" src="file:///F:\Program Files (x86)\WizNote\WizTools\htmleditor\core\wizEditor.js" wiz_style="unsave" charset="utf-8"></script><script type="text/javascript" src="file:///F:\Program Files (x86)\WizNote\WizTools\htmleditor\core\checklist\todo.js" wiz_style="unsave" charset="utf-8"></script><script type="text/javascript" src="file:///F:\Program Files (x86)\WizNote\WizTools\htmleditor\core\p_w_picpathresize\dragresize.js" wiz_style="unsave" charset="utf-8"></script><script type="text/javascript" src="file:///F:\Program Files (x86)\WizNote\WizTools\htmleditor\editorHelper.js" wiz_style="unsave" charset="utf-8"></script></head> shell


<body style="" contenteditable="true"><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">##變量</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">變量能夠由字母數字下劃線組成,數字不打頭。</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">bash爲弱類型語言,</span><span style="line-height: 1.6;">變量</span><span style="line-height: 1.6;">默認類型是字符串型。若是要進行數值運算,則須要指定類型。</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">變量須要=鏈接,=左右沒有空格,若變量的值有空格用引號。括起來。</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">變量能夠疊加`echo $aa &nbsp;aa="$aa"456 ` aa後再添456也能夠`aa=${aa}456`</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">環境變量的名稱建議寫大寫。</span></div><div style="background-color: rgb(255, 255, 255);"><font face="微軟雅黑">變量引用` ${name}, $name`</font></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">###bash變量的類型</span></div><div style="background-color: rgb(255, 255, 255);"><font face="微軟雅黑">本地變量:做用域僅爲當前shell進程,就是用戶自定義shell;</font></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">環境變量:做用域爲當前shell進程及其子進程,主要和操做系統環境相關的數據。</div><div style="background-color: rgb(255, 255, 255);"><font face="微軟雅黑">局部變量:做用域僅爲某代碼片段(函數上下文);</font></div><div style="background-color: rgb(255, 255, 255);"><font face="微軟雅黑"><br></font></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">位置參數變量:當執行腳本的shell進程傳遞的參數,向腳本中傳遞參數或數據,變量名不能自定義,做用是固定的;</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">預約義變量:bash中已經定義好的變量,變量名不能自定義,變量做用固定。</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">位參變量是預約義的一種。從上到下愈來愈嚴格。</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">***</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;"><br></span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">####本地變量</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">本地變量:</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">set &nbsp; &nbsp; &nbsp;//查看全部變量 &nbsp;unset刪除變量。</div><div style="background-color: rgb(255, 255, 255);"><font face="微軟雅黑">unset name</font><span style="font-family: 微軟雅黑; line-height: 1.6;">撤銷變量 ,此處並非引用。</span><br></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">***</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">####環境變量</span><span style="line-height: 1.6;">&nbsp;</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">#####變量聲明和賦值方法</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">```</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">1.export 變量名=變量值 &nbsp;//聲明爲全局變量。</span></div><div style="background-color: rgb(255, 255, 255);"><div><font face="微軟雅黑">2.name=value</font></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><font face="微軟雅黑">export name</font></div><div><font face="微軟雅黑"><div>3. declare -x name=value</div><div>4. name=value</div><div>declare -x name</div></font></div></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">```</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">##### 引用(同上)</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">&nbsp;${na &nbsp; &nbsp; &nbsp; &nbsp;me}</span></div><div style="background-color: rgb(255, 255, 255);"><div><font face="微軟雅黑">查看環境變量:`export, declare -x, printenv, env`</font></div><div><font face="微軟雅黑">撤銷環境變量:`unset name`</font></div></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">在當前shell和子shell中生效,寫入配置文件中對全部shell生效。</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">父shell的環境下,新建shell爲子shell。直接輸xxshell</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">&nbsp; &nbsp;`&nbsp;</span><span style="font-size: 15px; line-height: 1.6;">pstree &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//肯定shell位置` &nbsp;&nbsp;</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">&nbsp; &nbsp; `</span>env &nbsp;變量名 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//查詢環境變量`</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">&nbsp; &nbsp;`&nbsp;</span>unset &nbsp;變量名 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//刪除變`</div><div style="background-color: rgb(255, 255, 255);"><div><font face="微軟雅黑">注意:bash內嵌了許多環境變量(一般爲全大寫字符),用於定義bash的工做環境</font>:<span style="font-family: 微軟雅黑; line-height: 1.6;">PATH, HISTFILE, HISTSIZE, HISTFILESIZE, HISTCONTROL, SHELL, HOME, UID, PWD, OLDPWD</span></div></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">PATH:用冒號分割的路徑,系統命令所在。</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="background-color: inherit; line-height: 1.5; font-size: 15px;">本身的腳本不要拷到系統目錄下,應該PATH="$PATH":/root &nbsp;追加&nbsp; &nbsp; &nbsp; &nbsp;</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">PS1;,系統定義提示符的變量,就是shell提示符,雖然不是環境變量,</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">***</div><div style="background-color: rgb(255, 255, 255);"><div><font face="微軟雅黑">####只讀變量</font></div><div><font face="微軟雅黑">(1) declare -r name</font></div><div><font face="微軟雅黑">(2) readonly name</font></div></div><div style="background-color: rgb(255, 255, 255);"><font face="微軟雅黑">只讀變量沒法從新賦值,而且不支持撤銷;存活時間爲當前shell進程的生命週期,隨shell進程終止而終止;</font></div><div style="background-color: rgb(255, 255, 255);">***</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">###bash算術運算</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">注:(由於bash中默認類型爲字符型,須要自行設定纔可運算)</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">算術運算符:`+ &nbsp;- * / &nbsp;% **`<span style="line-height: 1.6;"><br></span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">```</span><br></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 1.6;">&nbsp;declare&nbsp;[+或-] [選項] 變量名</span><br></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><div>&nbsp;<span style="line-height: 1.6;">&nbsp; &nbsp;</span><span style="line-height: 1.6;">-</span><span style="line-height: 1.6;">給變量設定類型屬性 &nbsp;+取消變量的類型屬性&nbsp;</span></div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">-i &nbsp;將變量聲明爲整型 &nbsp;&nbsp;</span></div><div>&nbsp; &nbsp; -x &nbsp; 將變量聲明爲環境變量 &nbsp;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">-p 顯示指定變量被聲明的類型</span></div><div>&nbsp;&nbsp;declare &nbsp;-i cc=$aa+$bb &nbsp;<br></div><div>```</div><div>####算術運算的方式:<span style="line-height: 22px;">&nbsp;&nbsp;</span></div><div><span style="line-height: 22px;">支持通常運算符,邏輯運算符</span></div><div>1. &nbsp;`<span style="line-height: 1.6;">let VAR=$num1 or $num2` &nbsp;bash內建命令,一般用於運算</span><span style="line-height: 1.6;">&nbsp;&nbsp;</span></div><div><span style="background-color: inherit; line-height: 1.5;">2. &nbsp;`VAR=</span><span style="line-height: 1.6;">$[</span><span style="line-height: 1.6;">experssion</span><span style="line-height: 1.6;">]`&nbsp;</span><span style="line-height: 1.6; color: rgb(255, 0, 0);">(最經常使用)</span></div><div><span style="line-height: 22px;">3. `VAR=</span><span style="line-height: 1.6;">$((</span><span style="line-height: 1.6;">experssion</span><span style="line-height: 1.6;">))`&nbsp;</span></div><div><span style="line-height: 1.6;">4.&nbsp;</span><span style="line-height: 1.6;">`VAR=$(expr a + b &nbsp;)` &nbsp; //此處的表達式須要空格分割</span><span style="line-height: 1.6;">&nbsp;</span></div><div><span style="line-height: 1.6;">例:&nbsp;</span></div><div><span style="line-height: 1.6;">&nbsp;` ff=$(($aa+$bb))` &nbsp;//其中的空格有沒有都行 ,</span><span style="background-color: inherit; line-height: 1.5;">&nbsp;單括號括起來的是系統命令 &nbsp;</span><span style="background-color: inherit; line-height: 1.5;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></div></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="line-height: 22px;">&nbsp;`dd=$(expr $aa + $bb)` &nbsp; //把括號裏的命令結果賦dd</span><br></div><div style="background-color: rgb(255, 255, 255);"><div><font face="微軟雅黑">注意:有些時候乘法符號須要轉義;</font><span style="font-family: 微軟雅黑; white-space: pre; line-height: 1.6;"> </span></div><div><font face="微軟雅黑">####加強型賦值:</font></div><div><font face="微軟雅黑">變量作某種算術運算後回存至此變量中;</font></div><div><font face="微軟雅黑">```</font></div><div><font face="微軟雅黑">`let i=$i+#` &nbsp;</font><span class="Apple-tab-span" style="font-family: 微軟雅黑; line-height: 1.6; white-space: pre;"> </span>`<span style="font-family: 微軟雅黑; line-height: 1.6;">let i+=#`</span></div><div><font face="微軟雅黑">`+=,-=,*=, /=, %=`</font><span style="font-family: 微軟雅黑; white-space: pre; line-height: 1.6;"> </span></div><div><font face="微軟雅黑">自增:`</font><font face="微軟雅黑" style="line-height: 1.6;">VAR=$[$VAR+1]` ;`</font><span style="line-height: 1.6; font-family: 微軟雅黑;">let &nbsp;VAR+=1 &nbsp; `;`</span><span style="line-height: 1.6; font-family: 微軟雅黑;">let &nbsp;VAR++`</span></div><div><font face="微軟雅黑">自減:`</font><span style="font-family: 微軟雅黑; line-height: 1.6;">VAR=$[$VAR-1]`; ` &nbsp;</span><span style="font-family: 微軟雅黑; line-height: 1.6;">let &nbsp;VAR-=1`;`</span><span style="font-family: 微軟雅黑; line-height: 1.6;">let &nbsp;VAR--`</span></div></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">```</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">***</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">####條件測試</div><div style="background-color: rgb(255, 255, 255);"><div><font face="微軟雅黑">條件測試:</font><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="font-family: 微軟雅黑; line-height: 1.6;">判斷某需求是否知足,須要由測試機制來實現;</span></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;">如何編寫測試表達式以實現所需的測試:</span><br></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><font face="微軟雅黑">(1) 執行命令,並利用命令狀態返回值來判斷;</font></div><div><font face="微軟雅黑"><span class="Apple-tab-span" style="white-space:pre"> </span>0:成功&nbsp;</font><span class="Apple-tab-span" style="font-family: 微軟雅黑; line-height: 1.6; white-space: pre;"> </span><span style="font-family: 微軟雅黑; line-height: 1.6;">1-255:失敗</span></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><font face="微軟雅黑">(2) 測試表達式</font></div><div><font face="微軟雅黑"><span class="Apple-tab-span" style="white-space:pre"> </span>test &nbsp;EXPRESSION;</font><span class="Apple-tab-span" style="font-family: 微軟雅黑; line-height: 1.6; white-space: pre;"> </span><span style="font-family: 微軟雅黑; line-height: 1.6;">[ EXPRESSION ];</span><span class="Apple-tab-span" style="font-family: 微軟雅黑; line-height: 1.6; white-space: pre;"> </span><span style="font-family: 微軟雅黑; line-height: 1.6;">` EXPRESSION `;</span></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;">注意:EXPRESSION兩端必須有空白字符,不然爲語法錯誤;</span><span style="font-family: 微軟雅黑; line-height: 1.6;">上述命令並不會主動輸出結果,須要輸入`echo$?`來查看上一次判斷結果.</span><br></div><div><span class="Apple-tab-span" style="line-height: 1.6; white-space: pre;"><font face="微軟雅黑">*** </font></span><br></div><div><font face="微軟雅黑">#####bash的測試類型:</font></div><div><font face="微軟雅黑">數值測試;</font><span style="font-family: 微軟雅黑; line-height: 1.6;">字符串測試;</span><span style="font-family: 微軟雅黑; line-height: 1.6;">文件測試</span></div><div><font face="微軟雅黑">數值測試</font></div><div><font face="微軟雅黑">```</font></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-eq:是否等於; [ $num1 -eq $num2 ]</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp; -</span>ne:是否不等於;</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-gt:是否大於;</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-ge:是否大於等於;</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-lt:是否小於;</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-le:是否小於等於;</div></span></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;">```</span></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;"><br></span></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;"><div>字符串測試:</div><div>字符,變量比較的時候須要加引用;要使用[[]] &nbsp;不然會出現不可預期的狀況。</div><div>```</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>==:是否等於;</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>&gt;:是否大於;</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>&lt;:是否小於;</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>!=:是否不等於;</div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>=~:左側字符串是否可以被右側的PATTERN所匹配;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div></span><span style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-z "STRING":判斷指定的字串是否爲空;空則爲真,不空則假;</div></span><div style="font-family: 微軟雅黑; line-height: 1.6;"><span style="line-height: 1.6;">&nbsp; &nbsp;</span><span style="line-height: 1.6;">&nbsp;</span><span style="line-height: 1.6;">-n "STRING":判斷指定的字符串是否不空;不空則真,空則爲假;</span></div><div style="font-family: 微軟雅黑; line-height: 1.6;"><span style="line-height: 1.6;">```</span></div><div style="font-family: 微軟雅黑; line-height: 1.6;"><span style="line-height: 1.6;"><br></span></div><div style="font-family: 微軟雅黑; line-height: 1.6;">文件測試</div><div style="font-family: 微軟雅黑; line-height: 1.6;">```</div><div style="font-family: 微軟雅黑; line-height: 1.6;"><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>存在性測試</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">-a &nbsp;FILE</span></div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">-e &nbsp;FILE &nbsp;</span><span style="line-height: 1.6;">是否存在文件(是爲真);</span></div><div>文件的存在性測試,存在則爲真,不然則爲假;</div><div>存在性及類型測試</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-b &nbsp;FILE:是否存在而且爲 塊設備 文件;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-c &nbsp;FILE:是否存在而且爲 字符設備 文件;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-d &nbsp;FILE:是否存在而且爲 目錄文件;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-f &nbsp;FILE:是否存在而且爲 普通文件;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-h &nbsp;FILE或 -L &nbsp;FILE:是否存在而且爲 符號連接文件;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-p FILE:是否存在且爲 命名管道文件;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-S &nbsp;FILE:是否存在且爲 套接字文件;</div><div>文件權限測試:</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-r &nbsp;FILE:是否存在而且 對當前用戶可讀;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-w &nbsp;FILE:是否存在而且 對當前用戶可寫;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-x &nbsp;FILE:是否存在而且 對當前用戶可執行;</div><div>特殊權限測試:</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-u &nbsp;FILE:是否存在而且 擁有suid權限;用很少</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-g &nbsp;FILE:是否存在而且 擁有sgid權限;<span style="line-height: 1.6;">用很少&nbsp;</span></div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-k &nbsp;FILE:是否存在而且 擁有sticky權限;<span style="line-height: 1.6;">用很少</span></div><div>文件是否有內容:</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-s &nbsp;FILE:是否有內容;</div><div>時間戳:</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-N FILE:文件自從上一次讀操做後是否被修改過;</div><div>從屬關係測試:</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-O &nbsp;FILE:當前用戶是否爲文件的屬主;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>-G &nbsp;FILE:當前用戶是否屬於文件的屬組;</div><div>雙目測試:</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>FILE1 &nbsp;-ef &nbsp;FILE2:1與2是否指向同一個文件系統的相同inode的硬連接,<span style="line-height: 1.6;">inode號一致</span><span style="line-height: 1.6;">;</span></div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>FILE1 &nbsp;-nt &nbsp;FILE2:FILE1是否新於FILE2;</div><div><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span>FILE1 &nbsp;-ot &nbsp;FILE2:FILE1是否舊於FILE2;</div></div><div style="font-family: 微軟雅黑; line-height: 1.6;">```</div><div style="font-family: 微軟雅黑; line-height: 1.6;">***</div><div style="font-family: 微軟雅黑; line-height: 1.6;"><div>####邏輯組合運算:</div><div>這樣的執行也反映在CLI中。邏輯優先級非&gt;與&gt;或.</div><div>第一種方式:</div><div>```</div><div>COMMAND1 &amp;&amp; COMMAND2<span style="line-height: 21.8125px;">&nbsp; &nbsp; 1對2才執行</span></div><div>COMMAND1 || COMMAND2 &nbsp; &nbsp;<span style="line-height: 21.8125px;">1不對2執行</span></div><div>! COMMAND&nbsp;</div><div><span style="line-height: 1.6;">[ -O FILE ] &amp;&amp; [ -r FILE ]</span><br></div><div><span style="line-height: 21.8125px;">命令1;命令2 &nbsp; &nbsp;前後執行</span><br></div><div><span style="line-height: 21.8125px;">```</span></div><div><span style="line-height: 1.6;">第二種方式:</span><br></div><div>```</div><div>EXPRESSION1 &nbsp;-a &nbsp;EXPRESSION2 &nbsp; &nbsp;<span style="line-height: 1.6;">邏輯與,判斷1和判斷2都成立,結果才爲真</span></div><div>EXPRESSION1 &nbsp;-o &nbsp;EXPRESSION2 &nbsp;&nbsp;<span style="line-height: 1.6;">邏輯或, 判斷1和判斷2有一個爲真就是真</span></div><div>! EXPRESSION &nbsp; &nbsp;<span style="line-height: 1.6;">邏輯非,原判斷式取反</span></div><div><span style="line-height: 1.6;">[ -O FILE -a -x FILE ]</span><br></div></div><div style="font-family: 微軟雅黑; line-height: 1.6;"><span style="line-height: 21.8125px;">命令1&amp;&amp; 命令2||命令3 &nbsp; 1對執行2,1不對,執行3</span><br></div><div><div style="font-family: 微軟雅黑; line-height: 21.81818199157715px; font-size: 15.454545021057129px;">```</div><div style="font-family: 微軟雅黑; line-height: 21.81818199157715px; font-size: 15.454545021057129px;">***</div><div><div><span style="line-height: 21.8125px; font-family: 微軟雅黑;">向腳本傳遞參數:</span><br></div><div><font face="微軟雅黑"><span style="line-height: 21.8125px;">位置參數變量</span></font><span style="font-family: 微軟雅黑; line-height: 1.6;">(只能夠改動值,系統定義好的功能)</span></div><div><span style="line-height: 1.6; font-family: 微軟雅黑;">```</span></div><div><span style="line-height: 1.6; font-family: 微軟雅黑;">$n &nbsp; &nbsp;n爲數字,$0表明命令自己,$1-$9表明第一到九個參數,十以上的參數須要大括號包含如${} &nbsp; &nbsp;</span><span style="line-height: 1.6; font-family: 微軟雅黑;">&nbsp;</span><br></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;">$1...接受腳本外傳入的參數。</span></div><div><span style="line-height: 21.8125px; font-family: 微軟雅黑;">輪替:`</span><span style="line-height: 21.8125px; font-family: 微軟雅黑;">shift &nbsp;[n]`:位置參數輪替;剔除前幾個參數。</span></div></div><div style="font-family: 微軟雅黑; line-height: 21.81818199157715px; font-size: 15.454545021057129px;"><div style="line-height: 24px;">```</div><div style="line-height: 24px;">特殊變量:</div><div style="line-height: 24px;">```</div><div style="line-height: 24px;">$* &nbsp; 全部參數,$*把全部參數當作一個總體,只會傳入一次,一次所有傳入。</div><div style="line-height: 24px;">$@ 全部參數,不過$@把每一個參數區分對待,給幾個傳幾回。</div><div style="line-height: 24px;">$# &nbsp; 全部參數的個數。 計算傳入腳本的參數個數。 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div style="line-height: 24px;">&nbsp;</div><div style="line-height: 24px;"><span style="font-size: 15.454545021057129px;">$$當前進程的PID</span></div><div style="line-height: 24px;">$!返回最後一個後臺進程的PID</div><div style="line-height: 24px;"><span style="font-size: 15.454545021057129px; line-height: 21.81818199157715px;">``` &nbsp; &nbsp;&nbsp;</span></div></div><div style="font-family: 微軟雅黑; line-height: 21.81818199157715px; font-size: 15.454545021057129px;">*** &nbsp; &nbsp; &nbsp; &nbsp;</div><div><font face="微軟雅黑"><span style="line-height: 21.8125px;">#####腳本的狀態返回值:</span></font></div><div><font face="微軟雅黑"><span style="line-height: 21.8125px;">默認是腳本中執行的最後一條件命令的狀態返回值;</span></font></div><div><span style="font-family: 微軟雅黑; line-height: 1.6;">`$#` 最後一個命令的返回狀態 (0-255) 返回0表示執行正確,命令找不到127,文件找不到2.(程序識別任意)</span></div><div><font face="微軟雅黑"><span style="line-height: 21.8125px;">自定義狀態退出狀態碼:</span></font></div><div><font face="微軟雅黑"><span style="line-height: 21.8125px;">`exit &nbsp;[n]:n`爲本身指定的狀態碼;</span></font></div><div style="font-family: 微軟雅黑; line-height: 21.81818199157715px; font-size: 15.454545021057129px;">注意:shell進程遇到exit時,即會終止,所以,整個腳本執行即爲結束; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="font-family: 微軟雅黑; line-height: 21.81818199157715px; font-size: 15.454545021057129px;">*** &nbsp; &nbsp; &nbsp;&nbsp;</div></div></div></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">\d &nbsp;顯示日期,格式爲「星期 月 日」</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">\h &nbsp;顯示簡寫主機名,如默認主機名「localhost」</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">\t &nbsp; 顯示24小時制時間,格式 HH:MM:SS</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">\T &nbsp;顯示12小時制時間,格式同上</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">\A &nbsp;顯示24小時,格式爲HH:MM</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">\u &nbsp;顯示當前用戶</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">\w &nbsp;顯示當前所在目錄的完整名稱</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">\W 顯示當前所在目錄的最後一個目錄。</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">\# &nbsp; 執行的第幾個命令</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">\$ &nbsp; 提示符若是是root會顯示提示符爲「#」,普通用戶顯示爲「$」&nbsp;</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eg#PS1 &nbsp;顯示當前提示符。本身改PS1=‘[]'</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><br></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">###bash腳本編程之用戶交互:</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">####read參數</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">```</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="font-size: 15px; line-height: 1.6;">read[選項][變量名]</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">&nbsp; -p 「PROMPT提示信息」: 在等待read輸入時,輸出提示信息&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">&nbsp; -t &nbsp;TIMEOUT &nbsp; : &nbsp; read命令會一直等待用戶輸入,使用此選項能夠指定等待時間</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">&nbsp; -n &nbsp;字符數: &nbsp; &nbsp;read命令只接受指定的字符數,就會執行</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">&nbsp; -s : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 隱藏輸入數據,適用於機密信息的輸入&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">``` &nbsp;</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">####<span style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif; line-height: 1.6;">echo用法</span></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">```</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">echo [OPTION]...「 {轉義符}[輸出內容] 」</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">&nbsp; &nbsp; &nbsp; -e &nbsp;支持轉義符</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;"><span style="line-height: 1.6;">先添選項-e,在輸出內容裏添加轉義符。</span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;"><span style="line-height: 1.6;">轉義符</span><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">輸出</span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;"><span style="line-height: 1.6;">\\</span><span style="line-height: 1.6;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="line-height: 1.6;">輸出\自己</span><br></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">\a<span style="line-height: 1.6;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="line-height: 1.6;">輸出警告音</span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">\b&nbsp;<span style="line-height: 1.6;">&nbsp; &nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">退格</span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">\c<span style="line-height: 1.6;">&nbsp; &nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">取消輸出行末尾的轉換符,和「-n」選項同樣</span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">\f<span style="line-height: 1.6;">&nbsp; &nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">換頁</span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">\n<span style="line-height: 1.6;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">換行</span><br></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">\r<span style="line-height: 1.6;">&nbsp; &nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">回車</span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">\e &nbsp; &nbsp; &nbsp;escape鍵<br>\t &nbsp; &nbsp; &nbsp;水平製表符,<br>\v<span style="line-height: 1.6;">&nbsp; &nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">垂直製表符</span><br></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">\0nnn<span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">按照八進制ASCII表輸出字符,0爲數字0,nnn是三位八進制數</span><span style="line-height: 1.6;"><br></span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;"><span style="line-height: 1.6;">\xhh</span><span style="line-height: 1.6;">&nbsp; &nbsp;&nbsp;</span><span style="line-height: 1.6;">按照十六進制ASCII表輸出字符,其中hh是倆位十六進制數</span></div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">```</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">echo默認結尾沒有換行,print默認有換行符</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">***</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">#####echo的字符顏色</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">&nbsp;`echo -e "\e[31m &nbsp;abcd \e[0m" ` &nbsp; //輸出紅色字符abcd,31m表顏色,\e[31m起始 &nbsp; &nbsp; \e[0m"</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">支持顏色</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">30m=黑色 &nbsp; 31m=紅色 &nbsp; 32m=綠色 &nbsp; 33=*** &nbsp;34m=藍色 &nbsp;35m=洋紅色 &nbsp;36m=青色</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">37m=白色</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;">***</div><div style="font-family: Helvetica, 'Hiragino Sans GB', 微軟雅黑, 'Microsoft YaHei UI', SimSun, SimHei, arial, sans-serif;"><div style="font-family: 微軟雅黑;">####printf&nbsp;</div><div style="font-family: 微軟雅黑;">```</div><div style="font-family: 微軟雅黑;">printf‘打印格式’ 實際內容 &nbsp; &nbsp;%s字符串 &nbsp;%f 浮點</div><div style="font-family: 微軟雅黑;">&nbsp; &nbsp; &nbsp; \a 警告聲音輸出 &nbsp; &nbsp; &nbsp;\b退格鍵(backspace) &nbsp; \f &nbsp;清屏 &nbsp; &nbsp; &nbsp;\n換行&nbsp; &nbsp; &nbsp; &nbsp; \r enter鍵 &nbsp; &nbsp; &nbsp;</div><div style="font-family: 微軟雅黑;">&nbsp; &nbsp; &nbsp; \t &nbsp;水平tab鍵(製表符,空格) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\v 垂直tab鍵 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\xNN NN爲兩位數字按鍵 轉數字爲字符</div><div style="font-family: 微軟雅黑;">不加‘’輸出只認第一個格式輸出符,後面也不能加文件名和管道。</div><div>```</div><div>***</div></div></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><span style="background-color: inherit; line-height: 1.5;">&nbsp; &nbsp; &nbsp; &nbsp; 變量測試和替換</span></div><table border="1" cellpadding="2" cellspacing="0" style="font-size: inherit; margin-top: 10px; margin-bottom: 10px; background-color: rgb(255, 255, 255); font-family: 微軟雅黑; width: 600px;"><tbody style="background-color: inherit;"><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;">變量置換方式</td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">變量y沒有設置</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">變量y爲空值</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">變量y設置值</div></td></tr><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;">x=${y-新值}</td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=新值</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x爲空</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=$y</div></td></tr><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=${y:-新值}</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=新值</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=新值</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=$y</div></td></tr><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 33px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=${y+新值}</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 33px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x爲空</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 33px; background-color: inherit; width: 129px;">x=新值</td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 33px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=新值</div></td></tr><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=${y:+新值}</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x爲空</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x爲空</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=新值</div></td></tr><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=${y=新值}</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=新值</div><div style="min-width: 2px; background-color: inherit;">y=新值</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x爲空</div><div style="min-width: 2px; background-color: inherit;">y值不變</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=$y</div><div style="min-width: 2px; background-color: inherit;">y值不變</div></td></tr><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;">x=${y:=新值}</td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=新值</div><div style="min-width: 2px; background-color: inherit;">y=新值</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=新值</div><div style="min-width: 2px; background-color: inherit;">y=新值</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 25px; background-color: inherit; width: 129px;">x=$y<br style="background-color: inherit;">y值不變<br style="background-color: inherit;"></td></tr><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 28px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=${y?新值}</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 28px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">新值輸出到標準錯誤輸出(就是屏幕)</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 28px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x爲空</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 28px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=$y</div></td></tr><tr style="background-color: inherit;"><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 28px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=${y:?新值}</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 28px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">新值輸出到標準錯誤輸出</div></td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 28px; background-color: inherit; width: 129px;">新值輸出到標準錯誤輸出</td><td valign="top" style="word-break: break-all; border-color: rgb(153, 153, 153); padding: 5px 16px 5px 12px; min-height: 25px; min-width: 25px; height: 28px; background-color: inherit; width: 129px;"><div style="min-width: 2px; background-color: inherit;">x=$y</div></td></tr></tbody></table><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><br style="background-color: inherit;"></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">注:程序使用,不須要記,多查。</div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;">測試方式中有沒有:的區別就是在Y爲空時候的對待方式。-+ 徹底相反。=會影響xy &nbsp;?結果輸出到屏幕。</div><div style="background-color: rgb(255, 255, 255);"><div><br></div></div><div style="background-color: rgb(255, 255, 255); font-family: 微軟雅黑;"><br></div></body></html> 編程

相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息