{"id":51979,"date":"2024-12-03T11:29:58","date_gmt":"2024-12-03T03:29:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/51979\/"},"modified":"2024-12-03T11:29:58","modified_gmt":"2024-12-03T03:29:58","slug":"linux%e4%b8%ad%e7%9a%84%e7%89%b9%e6%ae%8a%e5%ad%97%e7%ac%a6%e5%8f%8a%e5%90%ab%e4%b9%89%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/51979\/","title":{"rendered":"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48<\/h1>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300alinux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<\/p>\n<blockquote>\n<p>linux\u7684\u7279\u6b8a\u5b57\u7b26\uff1a1\u3001\u201c#\u201d\u6ce8\u91ca\u5b57\u7b26\uff1b2\u3001\u201c~\u201d\uff0c\u4ee3\u8868\u7528\u6237\u7684home\u76ee\u5f55\uff1b3\u3001\u201c;\u201d\uff0c\u662f\u62c5\u4efb\u201c\u8fde\u7eed\u6307\u4ee4\u201d\u529f\u80fd\u7684\u7b26\u53f7\uff1b4\u3001\u201c\/\u201d\uff0c\u8def\u5f84\u76ee\u5f55\u5206\u9694\u7b26\uff1b5\u3001\u201c\\\u201d\uff0c\u8f6c\u4e49\u7b26\uff1b6\u3001\u201c|\u201d\uff0c\u7ba1\u9053\u7b26\uff1b7\u3001\u201c.\u201d\uff0c\u4ee3\u8868\u5f53\u524d\u76ee\u5f55\uff1b8\u3001\u201c..\u201d\uff0c\u4ee3\u8868\u7236\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u5f53\u524d\u76ee\u5f55\u7684\u4e0a\u4e00\u7ea7\u76ee\u5f55\uff1b9\u3001\u201c?\u201d\uff0c\u6307\u7684\u662f\u5355\u5b57\u7b26\u901a\u914d\u7b26\uff0c\u4ee3\u8868\u6587\u4ef6\u540d\u4e2d\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u7684\u5339\u914d\uff1b10\u3001\u201c*\u201d\uff0c\u4ee3\u8868\u4efb\u610f\u5b57\u7b26\u5e8f\u5217\uff0c\u5339\u914d\u4efb\u610f\u5b57\u7b26\u7b49\u3002<\/p>\n<\/blockquote>\n<h3><strong>linux\u7279\u6b8a\u7b26\u53f7\u4f7f\u7528\u53ca\u542b\u4e49<\/strong><\/h3>\n<p><strong>#\uff1a<\/strong><\/p>\n<p>\u4ee5 # \u5f00\u5934\uff0c\u4ee3\u8868\u8fd9\u53e5\u8bdd\u662f\u6ce8\u91ca\u3002<\/p>\n<pre>#\uff01\/bin\/bash&nbsp;\u5e38\u51fa\u73b0\u5728\u547d\u4ee4\u4e4b\u524d\uff0c\u6216\u8005\u547d\u4ee4\u4e4b\u540e\uff0c\u540e\u9762\u662f\u6ce8\u91ca\u6587\u5b57\uff0c\u4e0d\u4f1a\u88ab\u6267\u884c\n#\u5f53\u8f93\u5165\u7684\u547d\u4ee4\u4e0d\u60f3\u88ab\u6267\u884c\u65f6\u8f93\u5165\uff08#\uff09\u5c31\u884c\u4e86\n#This&nbsp;line&nbsp;is&nbsp;comments.\uff08\u8fd9\u662f\u4e00\u884c\u6ce8\u91ca\uff09<\/pre>\n<p>\u867d\u7136\u4e0a\u9762\u90a3\u6bb5\u8bdd\u5c31\u88ab\u5ffd\u7565\u4e86\uff0c\u4f46\u5b83\u8fd8\u662f\u4f1a\u6dfb\u52a0\u5230\u60a8\u7684\u547d\u4ee4\u5386\u53f2\u8bb0\u5f55\u4e2d\u3002<\/p>\n<p>\u66f4\u5389\u5bb3\u7684\u505a\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>\u5148\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u5e76\u7ed9\u5b83\u8d4b\u503c\u5b57\u7b26\u4e32 \u201camazing alvin\u201d<\/p>\n<pre>this_string=\"amazing&nbsp;alvin\"<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a53209fa30.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe\" \/><\/p>\n<p>${this_string#amazing} \u8fd4\u56de\u7684\u662f\u88ab\u6ce8\u91ca\u6389 amazing \u7684 this_string \u5b57\u7b26\u4e32\u53d8\u91cf\uff0c\u53ef\u4ee5 echo \u8f93\u51fa\u770b\u4e0b\u7ed3\u679c\uff1a<\/p>\n<pre>echo&nbsp;awsome&nbsp;${this_string#amazing}<\/pre>\n<p>amazing \u53ea\u662f\u88ab\u6ce8\u91ca\u6389\u800c\u5df2\uff0c\u5b83\u5e76\u672a\u88ab\u5220\u9664\uff0c\u53bb\u6389\u6ce8\u91ca\u5b83\u5c31\u56de\u6765\u4e86\uff1a<\/p>\n<pre>echo&nbsp;$this_string<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320a30d9.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe1\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe1\" \/><\/p>\n<p><strong>~<\/strong><\/p>\n<p>~ \u4ee3\u8868\u7528\u6237\u7684home\u76ee\u5f55\uff0c\u6307\u7684\u662f\u4e3b\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u7528\u6237\u7684\u4e2a\u4eba\u76ee\u5f55\uff0c\u65e0\u8bba\u4f60\u8eab\u5728\u4f55\u65b9\uff0c\u8f93\u5165 cd ~ \u5b83\u5c06\u5e26\u4f60\u56de\u5bb6\uff01<\/p>\n<pre>cd&nbsp;~<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320a6aa5.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe2\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe2\" \/><\/p>\n<p>\u66f4\u9ad8\u7aef\u7684\u73a9\u6cd5\u5c31\u662f\u5728\u5b83\u540e\u9762\u52a0\u4e0a\u5177\u4f53\u7684\u8def\u5f84\uff0c\u76f4\u63a5\u5b9a\u4f4d\u5230\u5bb6\u76ee\u5f55\u4e2d\u7684\u6307\u5b9a\u4f4d\u7f6e\uff0c\u662f\u4e0d\u662f\u5f88\u65b9\u4fbf\u5462\uff1f<\/p>\n<pre>cd&nbsp;~\/work\/archive<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320abc71.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe3\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe3\" \/><\/p>\n<p><strong>\uff1b\u5206\u53f7<\/strong><\/p>\n<p>\u5728 shell \u4e2d\uff0c\u62c5\u4efb&#8221;\u8fde\u7eed\u6307\u4ee4&#8221;\u529f\u80fd\u7684\u7b26\u53f7\u5c31\u662f&#8221;\u5206\u53f7&#8221;\u3002<\/p>\n<p>\u8fd9\u8ddf\u6211\u4eec\u65e5\u5e38\u4f7f\u7528\u7684 &#8220;;&#8221; \u5dee\u4e0d\u591a\uff0c\u5c31\u4e0d\u7ec6\u8bf4\u4e86\uff0c\u4e3b\u8981\u662f\u7528\u6765\u5206\u9694\u547d\u4ee4\u7684\u3002<\/p>\n<pre>ls&nbsp;&gt;&nbsp;count.txt;&nbsp;wc&nbsp;-l&nbsp;count.txt;&nbsp;rm&nbsp;count.txt<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320acd90.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe4\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe4\" \/><\/p>\n<p>\u8fd9\u91cc\u6ce8\u610f\uff0c\u7528 ; \u5206\u9694\u547d\u4ee4\u65f6\uff0c\u5373\u4f7f\u7b2c\u4e00\u4e2a\u547d\u4ee4\u5931\u8d25\uff0c\u7b2c\u4e8c\u4e2a\u547d\u4ee4\u4e5f\u4f1a\u8fd0\u884c\uff0c\u5373\u4f7f\u7b2c\u4e8c\u4e2a\u547d\u4ee4\u5931\u8d25\uff0c\u7b2c\u4e09\u4e2a\u547d\u4ee4\u4e5f\u4f1a\u8fd0\u884c\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002<\/p>\n<p>\u5982\u679c\u8981\u5728\u4e00\u4e2a\u547d\u4ee4\u5931\u8d25\u7684\u60c5\u51b5\u4e0b\u5c31\u505c\u6b62\uff0c\u8bf7\u4f7f\u7528 &#8220;&amp;&amp;&#8221; \uff0c\u5982\u4e0b\uff1a<\/p>\n<pre>cd&nbsp;.\/doesntexist&nbsp;&amp;&amp;&nbsp;cp&nbsp;~\/Documents\/reports\/*&nbsp;.<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320add73.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe5\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe5\" \/><\/p>\n<p><strong>\uff1b\uff1b\u8fde\u7eed\u5206\u53f7 (Terminator)<\/strong><\/p>\n<p>\u4e13\u7528\u5728 case \u7684\u9009\u9879\uff0c\u62c5\u4efb Terminator \u7684\u89d2\u8272\u3002<\/p>\n<pre>case&nbsp;\"$fop\"&nbsp;inhelp)&nbsp;echo&nbsp;\"Usage:&nbsp;Command&nbsp;-help&nbsp;-version&nbsp;filename\";;version)&nbsp;echo&nbsp;\"version&nbsp;0.1\"&nbsp;;;esac<\/pre>\n<p><strong>. dot<\/strong><\/p>\n<p>\u5728 shell \u4e2d\uff0c\u4f7f\u7528\u8005\u5e94\u8be5\u90fd\u6e05\u695a\uff0c\u4e00\u4e2a <code>.<\/code> \u4ee3\u8868\u5f53\u524d\u76ee\u5f55\uff0c\u4e24\u4e2a <code>..<\/code> \u4ee3\u8868\u4e0a\u5c42\u76ee\u5f55<\/p>\n<p>\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u5168\u90e8\u6587\u4ef6\uff1a<\/p>\n<pre>ls&nbsp;-al<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320b0837.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe6\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe6\" \/><\/p>\n<p>\u7ea2\u5708\u91cc\u7684 . \u5c31\u662f\u6307\u5f53\u524d\u76ee\u5f55\uff0c\u4e0d\u8fc7\u8fd9\u6ca1\u4ec0\u4e48\u610f\u4e49\uff0c\u6211\u4eec\u66f4\u591a\u7684\u662f\u5728\u547d\u4ee4\u4e2d\u4f7f\u7528\u5b83\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre>.\/script.sh<\/pre>\n<p>\u8fd9\u6837\u505a\u662f\u5728\u544a\u8bc9 bash \u53ea\u8981\u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u67e5\u627e\u5e76\u6267\u884c script.sh \u6587\u4ef6\u5c31\u597d\u4e86\uff0c\u4e0d\u7528\u5728\u8def\u5f84\u4e2d\u627e\u4e86\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320b5193.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe7\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe7\" \/><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u8981\u56de\u5230\u4e0a\u4e00\u7ea7\u76ee\u5f55\uff1a<\/p>\n<pre>cd&nbsp;..<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320b8825.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe8\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe8\" \/><\/p>\n<p>\u8ddf\u524d\u9762\u4e00\u6837\uff0c\u4f60\u53ef\u4ee5\u5728\u5b83\u540e\u9762\u52a0\u5177\u4f53\u7684\u76ee\u5f55\uff0c\u8fd9\u91cc\u7684\u610f\u601d\u5c31\u662f\u5b9a\u4f4d\u5230\u4e0e\u5f53\u524d\u76ee\u5f55\u540c\u7ea7\u7684\u5176\u5b83\u76ee\u5f55\uff1a<\/p>\n<pre>cd&nbsp;..\/projects\/<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320b98c7.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe9\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe9\" \/><\/p>\n<p><strong>\u2018string\u2019 \u5355\u5f15\u53f7 (\u5b57\u7b26\u4e32\u5355\u5f15\u53f7\uff09<\/strong><\/p>\n<p>\u88ab\u5355\u5f15\u53f7\u7528\u62ec\u4f4f\u7684\u5185\u5bb9\uff0c\u5c06\u88ab\u89c6\u4e3a\u5355\u4e00\u5b57\u4e32\u3002\u5728\u5f15\u53f7\u5185\u7684\u4ee3\u8868\u53d8\u6570\u7684$\u7b26\u53f7\uff0c\u6ca1\u6709\u4f5c\u7528\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u4ed6\u88ab\u89c6\u4e3a\u4e00\u822c\u7b26\u53f7\u5904\u7406\uff0c\u9632\u6b62\u4efb\u4f55\u53d8\u91cf\u66ff\u6362\u3002<\/p>\n<pre>hello&nbsp;world=hello&nbsp;world&nbsp;echo&nbsp;'$hello&nbsp;world'&nbsp;#&nbsp;We&nbsp;get&nbsp;$hello&nbsp;world<\/pre>\n<p><strong>\u201cstring\u201d \u53cc\u5f15\u53f7 (\u5b57\u7b26\u4e32\u53cc\u5f15\u53f7)<\/strong><\/p>\n<p>\u88ab\u53cc\u5f15\u53f7\u7528\u62ec\u4f4f\u7684\u5185\u5bb9\uff0c\u5c06\u88ab\u89c6\u4e3a\u5355\u4e00\u5b57\u4e32\u3002\u5b83\u9632\u6b62\u901a\u914d\u7b26\u6269\u5c55\uff0c\u4f46\u5141\u8bb8\u53d8\u91cf\u6269\u5c55\u3002\u8fd9\u70b9\u4e0e\u5355\u5f15\u6570\u7684\u5904\u7406\u65b9\u5f0f\u4e0d\u540c<\/p>\n<pre>heyyou=homeecho&nbsp;\"$heyyou\"&nbsp;#&nbsp;We&nbsp;get&nbsp;home<\/pre>\n<p><strong><code>command\uff08\u547d\u4ee4\uff09<\/code> \u5012\u5f15\u53f7 (\u53cd\u5f15\u53f7)<\/strong><\/p>\n<p>\u5728\u524d\u9762\u7684\u5355\u53cc\u5f15\u53f7\uff0c\u62ec\u4f4f\u7684\u662f\u5b57\u4e32\uff0c\u4f46\u5982\u679c\u8be5\u5b57\u4e32\u662f\u4e00\u5217\u547d\u4ee4\u5217\uff0c\u4f1a\u600e\u6837\uff1f\u7b54\u6848\u662f\u4e0d\u4f1a\u6267\u884c\u3002\u8981\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\uff0c\u6211\u4eec\u5f97\u7528\u5012\u5355\u5f15\u53f7\u6765\u505a\u3002<\/p>\n<pre>fdv=`date&nbsp;+%F`echo&nbsp;\"Today&nbsp;$fdv\"<\/pre>\n<p>\u5728\u5012\u5f15\u53f7\u5185\u7684 date +%F \u4f1a\u88ab\u89c6\u4e3a\u6307\u4ee4\uff0c\u6267\u884c\u7684\u7ed3\u679c\u4f1a\u5e26\u5165 fdv \u53d8\u6570\u4e2d\u3002<\/p>\n<p><strong>, \u9017\u70b9 (comma\uff0c\u6807\u70b9\u4e2d\u7684\u9017\u53f7)<\/strong><\/p>\n<pre>\u8fd9\u4e2a\u7b26\u53f7\u5e38\u8fd0\u7528\u5728\u8fd0\u7b97\u5f53\u4e2d\u5f53\u505a\"\u533a\u9694\"\u7528\u9014\u3002\u4f8btouch&nbsp;f{1,2,3}<\/pre>\n<p><strong>\/ \u659c\u7ebf (forward slash)\uff1a<\/strong><\/p>\n<p>\u5728\u8def\u5f84\u8868\u793a\u65f6\uff0c\u4ee3\u8868\u76ee\u5f55\u3002\u901a\u5e38\u5355\u4e00\u7684 \/ \u4ee3\u8868 root \u6839\u76ee\u5f55\u7684\u610f\u601d<\/p>\n<p>\u659c\u6760 &#8220;\/&#8221; \u6307\u7684\u662f\u8def\u5f84\u76ee\u5f55\u5206\u9694\u7b26\uff0c\u8fd9\u91cc\u6ca1\u4ec0\u4e48\u597d\u8bf4\u7684\u3002<\/p>\n<pre>ls&nbsp;~\/work\/tests\/<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320bc3e6.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe10\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe10\" \/><\/p>\n<p>\u4f46\u662f\uff0c\u6709\u610f\u601d\u7684\u662f\uff0c\u5982\u679c \/ \u8def\u5f84\u76ee\u5f55\u5206\u9694\u7b26\u524d\u9762\u6ca1\u6709\u4e1c\u897f\u7684\u8bdd\uff0c\u662f\u4e0d\u662f\u5c31\u662f\u610f\u5473\u7740\u8fd9\u662f\u6700\u4e0a\u7ea7\u7684\u76ee\u5f55\u4e86\uff1f\u7531\u4e8e Linux \u7cfb\u7edf\u7684\u76ee\u5f55\u6811\u5747\u59cb\u4e8e \/ \uff0c\u6240\u4ee5\u4ec5\u4ec5\u4e00\u4e2a \/ \u4ee3\u8868\u4e86\u6211\u4eec\u5e38\u8bf4\u7684\u7cfb\u7edf\u6839\u76ee\u5f55\u3002<\/p>\n<pre>cd&nbsp;\/<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20240401\/1711952672660a5320bfa01.jpg\" class=\"aligncenter\" title=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe11\" alt=\"linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u63d2\u56fe11\" \/><\/p>\n<p><strong>\\ \u5012\u659c\u7ebf(\u8f6c\u4e49\u7b26)<\/strong><\/p>\n<p>\u5728\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u7684escape \u5b57\u5143\uff0c\u6709\u51e0\u4e2a\u4f5c\u7528\uff1b\u653e\u5728\u6307\u4ee4\u524d\uff0c\u6709\u53d6\u6d88 aliases\u7684\u4f5c\u7528\uff1b\u653e\u5728\u7279\u6b8a\u7b26\u53f7\u524d\uff0c\u5219\u8be5\u7279\u6b8a\u7b26\u53f7\u7684\u4f5c\u7528\u6d88\u5931\uff1b\u653e\u5728\u6307\u4ee4\u7684\u6700\u672b\u7aef\uff0c\u8868\u793a\u6307\u4ee4\u8fde\u63a5\u4e0b\u4e00\u884c\u3002<\/p>\n<pre>#&nbsp;type&nbsp;rmrm&nbsp;is&nbsp;aliased&nbsp;to&nbsp;`rm&nbsp;-i'#&nbsp;\\rm&nbsp;.\/*.log<\/pre>\n<p>\u4e0a\u4f8b\uff0c\u6211\u5728 rm \u6307\u4ee4\u524d\u52a0\u4e0a escape \u5b57\u5143\uff0c\u4f5c\u7528\u662f\u6682\u65f6\u53d6\u6d88\u522b\u540d\u7684\u529f\u80fd\uff0c\u5c06 rm \u6307\u4ee4\u8fd8\u539f\u3002<\/p>\n<pre>#&nbsp;bkdir=\/home#&nbsp;echo&nbsp;\"Backup&nbsp;dir,&nbsp;\\$bkdir&nbsp;=&nbsp;$bkdir\"Backup&nbsp;dir,$bkdir&nbsp;=&nbsp;\/home<\/pre>\n<p>\u4e0a\u4f8b echo \u5185\u7684 \\$bkdir\uff0cescape \u5c06 $ \u53d8\u6570\u7684\u529f\u80fd\u53d6\u6d88\u4e86\uff0c\u56e0\u6b64\uff0c\u4f1a\u8f93\u51fa $bkdir\uff0c\u800c\u7b2c\u4e8c\u4e2a $bkdir\u5219\u4f1a\u8f93\u51fa\u53d8\u6570\u7684\u5185\u5bb9 \/home\u3002<\/p>\n<p><strong>| \u7ba1\u9053 (pipeline)<\/strong><\/p>\n<p>pipeline \u662f UNIX \u7cfb\u7edf\uff0c\u57fa\u7840\u4e14\u91cd\u8981\u7684\u89c2\u5ff5\u3002\u8fde\u7ed3\u4e0a\u4e2a\u6307\u4ee4\u7684\u6807\u51c6\u8f93\u51fa\uff0c\u505a\u4e3a\u4e0b\u4e2a\u6307\u4ee4\u7684\u6807\u51c6\u8f93\u5165\u3002<\/p>\n<pre>who&nbsp;|&nbsp;wc&nbsp;-l<\/pre>\n<p>\u5584\u7528\u8fd9\u4e2a\u89c2\u5ff5\uff0c\u5bf9\u7cbe\u7b80 script\uff08\u811a\u672c\uff09 \u6709\u76f8\u5f53\u7684\u5e2e\u52a9<\/p>\n<p><strong>! \u611f\u53f9\u53f7(negate or reverse)<\/strong><\/p>\n<p>\u901a\u5e38\u4ee3\u8868\u53cd\u903b\u8f91\u7684\u4f5c\u7528\uff0c\u6bd4\u5982\u6761\u4ef6\u4fa6\u6d4b\u4e2d\u7528\uff0c!= \u6765\u4ee3\u8868&#8221;\u4e0d\u7b49\u4e8e&#8221;<\/p>\n<p>ls f[!1-9]\u4ee3\u8868\u663e\u793a\u9664\u4e86f0, f1 &#8230;. f9 \u8fd9\u51e0\u4e2a\u6587\u4ef6\u7684\u5176\u4ed6\u6587\u4ef6<\/p>\n<p><strong>:\u5192\u53f7<\/strong><\/p>\n<p>\u5728 bash \u4e2d\uff0c\u8fd9\u662f\u4e00\u4e2a\u5185\u5efa\u6307\u4ee4\uff1a&#8221;\u4ec0\u4e48\u4e8b\u90fd\u4e0d\u5e72&#8221;\uff0c\u4f46\u8fd4\u56de\u72b6\u6001\u503c 0<\/p>\n<pre>echo&nbsp;$?&nbsp;#&nbsp;\u56de\u5e94\u4e3a&nbsp;0\n:&nbsp;&gt;&nbsp;f.$$<\/pre>\n<p>\u4e0a\u9762\u8fd9\u4e00\u884c\uff0c\u76f8\u5f53\u4e8e cat \/dev\/null &gt;f.$$\u3002\u4e0d\u4ec5\u5199\u6cd5\u7b80\u77ed\u4e86\uff0c\u800c\u4e14\u6267\u884c\u6548\u7387\u4e5f\u597d\u4e0a\u8bb8\u591a\u3002<\/p>\n<p>\u6709\u65f6\uff0c\u4e5f\u4f1a\u51fa\u73b0\u4ee5\u4e0b\u8fd9\u7c7b\u7684\u7528\u6cd5<\/p>\n<pre>:&nbsp;${HOSTNAME?}&nbsp;${USER?}&nbsp;${MAIL?}<\/pre>\n<p>\u8fd9\u884c\u7684\u4f5c\u7528\u662f\uff0c\u68c0\u67e5\u8fd9\u4e9b\u73af\u5883\u53d8\u6570\u662f\u5426\u5df2\u8bbe\u7f6e\uff0c\u6ca1\u6709\u8bbe\u7f6e\u7684\u5c06\u4f1a\u4ee5\u6807\u51c6\u9519\u8bef\u663e\u793a\u9519\u8bef\u8baf\u606f\u3002\u50cf\u8fd9\u79cd\u68c0\u67e5\u5982\u679c\u4f7f\u7528\u7c7b\u4f3c test \u6216 if\u8fd9\u7c7b\u7684\u505a\u6cd5\uff0c\u57fa\u672c\u4e0a\u4e5f\u53ef\u4ee5\u5904\u7406\uff0c\u4f46\u90fd\u6bd4\u4e0d\u4e0a\u4e0a\u4f8b\u7684\u7b80\u6d01\u4e0e\u6548\u7387\u3002<\/p>\n<p>\u9664\u4e86\u4e0a\u8ff0\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u5730\u65b9\u5fc5\u987b\u4f7f\u7528\u5192\u53f7<\/p>\n<pre>PATH=$PATH:$HOME\/fbin:$HOME\/fperl:\/usr\/local\/mozilla<\/pre>\n<p>\u5728\u4f7f\u7528\u8005\u81ea\u5df1\u7684HOME \u76ee\u5f55\u4e0b\u7684 .bash_profile\u6216\u4efb\u4f55\u529f\u80fd\u76f8\u4f3c\u7684\u6863\u6848\u4e2d\uff0c\u8bbe\u5b9a\u5173\u4e8e&#8221;\u8def\u5f84&#8221;\u7684\u573a\u5408\u4e2d\uff0c\u6211\u4eec\u90fd\u4f7f\u7528\u5192\u53f7\uff0c\u6765\u505a\u533a\u9694\u3002<\/p>\n<p><strong>? \u95ee\u53f7 (wild card)<\/strong><\/p>\n<p>\u5728\u6587\u4ef6\u540d\u6269\u5c55(Filename expansion)\u4e0a\u626e\u6f14\u7684\u89d2\u8272\u662f\u5339\u914d\u4e00\u4e2a\u4efb\u610f\u7684\u5b57\u5143\uff0c\u4f46\u4e0d\u5305\u542b null \u5b57\u5143\u3002<\/p>\n<pre>#&nbsp;ls&nbsp;a?a1<\/pre>\n<p><strong>\u661f\u53f7 (wild card)<\/strong><\/p>\n<p>\u76f8\u5f53\u5e38\u7528\u7684\u7b26\u53f7\u3002\u5728\u6587\u4ef6\u540d\u6269\u5c55(Filename expansion)\u4e0a\uff0c\u5979\u7528\u6765\u4ee3\u8868\u4efb\u4f55\u5b57\u5143\uff0c\u5305\u542b null \u5b57\u5143\u3002<\/p>\n<pre>#&nbsp;ls&nbsp;a*a&nbsp;a1&nbsp;access_log<\/pre>\n<p>\u5728\u8fd0\u7b97\u65f6\uff0c\u5b83\u5219\u4ee3\u8868 &#8220;\u4e58\u6cd5&#8221;\u3002<\/p>\n<pre>let&nbsp;\"fmult=2*3\"<\/pre>\n<p>\u9664\u4e86\u5185\u5efa\u6307\u4ee4 let\uff0c\u8fd8\u6709\u4e00\u4e2a\u5173\u4e8e\u8fd0\u7b97\u7684\u6307\u4ee4expr\uff0c\u661f\u53f7\u5728\u8fd9\u91cc\u4e5f\u62c5\u4efb&#8221;\u4e58\u6cd5&#8221;\u7684\u89d2\u8272\u3002\u4e0d\u8fc7\u5728\u4f7f\u7528\u4e0a\u5f97\u5c0f\u5fc3\uff0c\u4ed6\u7684\u524d\u9762\u5fc5\u987b\u52a0\u4e0aescape \u5b57\u5143\u3002<\/p>\n<p><strong>** \u6b21\u65b9\u8fd0\u7b97<\/strong><\/p>\n<p>\u4e24\u4e2a\u661f\u53f7\u5728\u8fd0\u7b97\u65f6\u4ee3\u8868 &#8220;\u6b21\u65b9&#8221; \u7684\u610f\u601d\u3002<\/p>\n<pre>let&nbsp;\"sus=2**3\"echo&nbsp;\"sus&nbsp;=&nbsp;$sus\"&nbsp;#&nbsp;sus&nbsp;=&nbsp;8<\/pre>\n<p><strong>$ \u7f8e\u5143<\/strong><\/p>\n<p>\u53d8\u91cf\u66ff\u6362(Variable Substitution)\u7684\u4ee3\u8868\u7b26\u53f7\u3002<\/p>\n<pre>vrs=123echo&nbsp;\"vrs&nbsp;=&nbsp;$vrs\"&nbsp;#&nbsp;vrs&nbsp;=&nbsp;123<\/pre>\n<p>\u53e6\u5916\uff0c\u5728 Regular Expressions \u91cc\u88ab\u5b9a\u4e49\u4e3a &#8220;\u884c&#8221; \u7684\u6700\u672b\u7aef (end-of-line)\u3002\u8fd9\u4e2a\u5e38\u7528\u5728grep\u3001sed\u3001awk \u4ee5\u53ca vim(vi) \u5f53\u4e2d\u3002<\/p>\n<p><strong>${} \u53d8\u91cf\u7684\u6b63\u89c4\u8868\u8fbe\u5f0f<\/strong><\/p>\n<p>bash \u5bf9 ${} \u5b9a\u4e49\u4e86\u4e0d\u5c11\u7528\u6cd5\u3002\u4ee5\u4e0b\u662f\u53d6\u81ea\u7ebf\u4e0a\u8bf4\u660e\u7684\u8868\u5217 &nbsp; <\/p>\n<pre>${parameter:-word}&nbsp;&nbsp;&nbsp;${parameter:=word}&nbsp;&nbsp;&nbsp;${parameter:?word}&nbsp;&nbsp;&nbsp;${parameter:+word}&nbsp;&nbsp;&nbsp;${parameter:offset}&nbsp;&nbsp;&nbsp;${parameter:offset:length}&nbsp;&nbsp;&nbsp;${!prefix*}&nbsp;&nbsp;&nbsp;${#parameter}&nbsp;&nbsp;&nbsp;${parameter#word}&nbsp;&nbsp;&nbsp;${parameter##word}&nbsp;&nbsp;&nbsp;${parameter%word}&nbsp;&nbsp;&nbsp;${parameter%%word}&nbsp;&nbsp;&nbsp;${parameter\/pattern\/string}&nbsp;&nbsp;&nbsp;${parameter\/\/pattern\/string}<\/pre>\n<p><strong>$*<\/strong><\/p>\n<p>$* \u5f15\u7528script\u7684\u6267\u884c\u5f15\u7528\u53d8\u91cf\uff0c\u5f15\u7528\u53c2\u6570\u7684\u7b97\u6cd5\u4e0e\u4e00\u822c\u6307\u4ee4\u76f8\u540c\uff0c\u6307\u4ee4\u672c\u8eab\u4e3a0\uff0c\u5176\u540e\u4e3a1\uff0c\u7136\u540e\u4f9d\u6b64\u7c7b\u63a8\u3002\u5f15\u7528\u53d8\u91cf\u7684\u4ee3\u8868\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>$0,&nbsp;$1,&nbsp;$2,&nbsp;$3,&nbsp;$4,&nbsp;$5,&nbsp;$6,&nbsp;$7,&nbsp;$8,&nbsp;$9,&nbsp;${10},&nbsp;${11}.....<\/pre>\n<p>\u4e2a\u4f4d\u6570\u7684\uff0c\u53ef\u76f4\u63a5\u4f7f\u7528\u6570\u5b57\uff0c\u4f46\u4e24\u4f4d\u6570\u4ee5\u4e0a\uff0c\u5219\u5fc5\u987b\u4f7f\u7528 {} \u7b26\u53f7\u6765\u62ec\u4f4f<\/p>\n<p>$* \u5219\u662f\u4ee3\u8868\u6240\u6709\u5f15\u7528\u53d8\u91cf\u7684\u7b26\u53f7\u3002\u4f7f\u7528\u65f6\uff0c\u5f97\u89c6\u60c5\u51b5\u52a0\u4e0a\u53cc\u5f15\u53f7\u3002<\/p>\n<pre>echo&nbsp;\"$*\"<\/pre>\n<p>\u8fd8\u6709\u4e00\u4e2a\u4e0e $* \u5177\u6709\u76f8\u540c\u4f5c\u7528\u7684\u7b26\u53f7\uff0c\u4f46\u6548\u7528\u4e0e\u5904\u7406\u65b9\u5f0f\u7565\u4e3a\u4e0d\u540c\u7684\u7b26\u53f7<\/p>\n<p><strong>\uffe5@<\/strong><\/p>\n<p>$@ \u4e0e $* \u5177\u6709\u76f8\u540c\u4f5c\u7528\u7684\u7b26\u53f7\uff0c\u4e0d\u8fc7\u5979\u4eec\u4e24\u8005\u6709\u4e00\u4e2a\u4e0d\u540c\u70b9\u3002<\/p>\n<p>\u7b26\u53f7 $* \u5c06\u6240\u6709\u7684\u5f15\u7528\u53d8\u91cf\u89c6\u4e3a\u4e00\u4e2a\u6574\u4f53\u3002<\/p>\n<p>\u4f46\u7b26\u53f7 $@ \u5219\u4ecd\u65e7\u4fdd\u7559\u6bcf\u4e2a\u5f15\u7528\u53d8\u91cf\u7684\u533a\u6bb5\u89c2\u5ff5\u3002<\/p>\n<p><strong>$#<\/strong><\/p>\n<p>\u8fd9\u4e5f\u662f\u4e0e\u5f15\u7528\u53d8\u91cf\u76f8\u5173\u7684\u7b26\u53f7\uff0c\u5979\u7684\u4f5c\u7528\u662f\u544a\u8bc9\u4f60\uff0c\u5f15\u7528\u53d8\u91cf\u7684\u603b\u6570\u91cf\u662f\u591a\u5c11\u3002<\/p>\n<pre>echo&nbsp;\"$#\"<\/pre>\n<p><strong>$? \u72b6\u6001\u503c (status variable)<\/strong><\/p>\n<p>\u4e00\u822c\u6765\u8bf4\uff0cUNIX(linux) \u7cfb\u7edf\u7684\u8fdb\u7a0b\u4ee5\u6267\u884c\u7cfb\u7edf\u8c03\u7528exit()\u6765\u7ed3\u675f\u7684\u3002\u8fd9\u4e2a\u56de\u4f20\u503c\u5c31\u662fstatus\u503c\u3002\u56de\u4f20\u7ed9\u7236\u8fdb\u7a0b\uff0c\u7528\u6765\u68c0\u67e5\u5b50\u8fdb\u7a0b\u7684\u6267\u884c\u72b6\u6001\u3002<\/p>\n<p>\u4e00\u822c\u6307\u4ee4\u7a0b\u5e8f\u5018\u82e5\u6267\u884c\u6210\u529f\uff0c\u5176\u56de\u4f20\u503c\u4e3a 0\uff1b\u5931\u8d25\u4e3a 1\u3002<\/p>\n<pre>tar&nbsp;cvfz&nbsp;dfbackup.tar.gz&nbsp;\/home\/user&nbsp;&gt;&nbsp;\/dev\/nullecho\"$?\"$$<\/pre>\n<p>\u7531\u4e8e\u8fdb\u7a0b\u7684ID\u662f\u552f\u4e00\u7684\uff0c\u6240\u4ee5\u5728\u540c\u4e00\u4e2a\u65f6\u95f4\uff0c\u4e0d\u53ef\u80fd\u6709\u91cd\u590d\u6027\u7684 PID\u3002\u6709\u65f6\uff0cscript\u4f1a\u9700\u8981\u4ea7\u751f\u4e34\u65f6\u6587\u4ef6\uff0c\u7528\u6765\u5b58\u653e\u5fc5\u8981\u7684\u8d44\u6599\u3002\u800c\u6b64script\u4ea6\u6709\u53ef\u80fd\u5728\u540c\u4e00\u65f6\u95f4\u88ab\u4f7f\u7528\u8005\u4eec\u4f7f\u7528\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u56fa\u5b9a\u6587\u4ef6\u540d\u5728\u5199\u6cd5\u4e0a\u5c31\u663e\u7684\u4e0d\u53ef\u9760\u3002\u552f\u6709\u4ea7\u751f\u52a8\u6001\u6587\u4ef6\u540d\uff0c\u624d\u80fd\u7b26\u5408\u9700\u8981\u3002\u7b26\u53f7$$\u6216\u8bb8\u53ef\u4ee5\u7b26\u5408\u8fd9\u79cd\u9700\u6c42\u3002\u5b83\u4ee3\u8868\u5f53\u524dshell \u7684 PID\u3002<\/p>\n<pre>echo&nbsp;\"$HOSTNAME,&nbsp;$USER,&nbsp;$MAIL\"&nbsp;&gt;&nbsp;ftmp.$$<\/pre>\n<p>\u4f7f\u7528\u5b83\u6765\u4f5c\u4e3a\u6587\u4ef6\u540d\u7684\u4e00\u90e8\u4efd\uff0c\u53ef\u4ee5\u907f\u514d\u5728\u540c\u4e00\u65f6\u95f4\uff0c\u4ea7\u751f\u76f8\u540c\u6587\u4ef6\u540d\u7684\u8986\u76d6\u73b0\u8c61\u3002<\/p>\n<p>ps: \u57fa\u672c\u4e0a\uff0c\u7cfb\u7edf\u4f1a\u56de\u6536\u6267\u884c\u5b8c\u6bd5\u7684 PID\uff0c\u7136\u540e\u518d\u6b21\u4f9d\u9700\u8981\u5206\u914d\u4f7f\u7528\u3002\u6240\u4ee5 script \u5373\u4f7f\u4e34\u65f6\u6587\u4ef6\u662f\u4f7f\u7528\u52a8\u6001\u6863\u540d\u7684\u5199\u6cd5\uff0c\u5982\u679cscript \u6267\u884c\u5b8c\u6bd5\u540e\u4ecd\u4e0d\u52a0\u4ee5\u6e05\u9664\uff0c\u4f1a\u4ea7\u751f\u5176\u4ed6\u95ee\u9898\u3002<\/p>\n<p><strong>( ) \u6307\u4ee4\u7fa4\u7ec4 (command group)<\/strong><\/p>\n<p>\u7528\u62ec\u53f7\u5c06\u4e00\u4e32\u8fde\u7eed\u6307\u4ee4\u62ec\u8d77\u6765\uff0c\u8fd9\u79cd\u7528\u6cd5\u5bf9 shell \u6765\u8bf4\uff0c\u79f0\u4e3a\u6307\u4ee4\u7fa4\u7ec4\u3002\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a(cd ~ ; vcgh=`pwd` ;echo $vcgh)\uff0c\u6307\u4ee4\u7fa4\u7ec4\u6709\u4e00\u4e2a\u7279\u6027\uff0cshell\u4f1a\u4ee5\u4ea7\u751f subshell\u6765\u6267\u884c\u8fd9\u7ec4\u6307\u4ee4\u3002\u56e0\u6b64\uff0c\u5728\u5176\u4e2d\u6240\u5b9a\u4e49\u7684\u53d8\u6570\uff0c\u4ec5\u4f5c\u7528\u4e8e\u6307\u4ee4\u7fa4\u7ec4\u672c\u8eab\u3002\u6211\u4eec\u6765\u770b\u4e2a\u4f8b\u5b50<\/p>\n<pre>#&nbsp;cat&nbsp;ftmp-01#!\/bin\/basha=fsh(a=incg&nbsp;;&nbsp;echo&nbsp;-e&nbsp;\"\\n&nbsp;$a&nbsp;\\n\")echo&nbsp;$a#.\/ftmp-01incgfsh<\/pre>\n<p>\u9664\u4e86\u4e0a\u8ff0\u7684\u6307\u4ee4\u7fa4\u7ec4\uff0c\u62ec\u53f7\u4e5f\u7528\u5728 array \u53d8\u6570\u7684\u5b9a\u4e49\u4e0a\uff1b\u53e6\u5916\u4e5f\u5e94\u7528\u5728\u5176\u4ed6\u53ef\u80fd\u9700\u8981\u52a0\u4e0aescape\u5b57\u5143\u624d\u80fd\u4f7f\u7528\u7684\u573a\u5408\uff0c\u5982\u8fd0\u7b97\u5f0f\u3002<\/p>\n<p><strong>(( ))<\/strong><\/p>\n<p>\u8fd9\u7ec4\u7b26\u53f7\u7684\u4f5c\u7528\u4e0e let \u6307\u4ee4\u76f8\u4f3c\uff0c\u7528\u5728\u7b97\u6570\u8fd0\u7b97\u4e0a\uff0c\u662f bash \u7684\u5185\u5efa\u529f\u80fd\u3002\u6240\u4ee5\uff0c\u5728\u6267\u884c\u6548\u7387\u4e0a\u4f1a\u6bd4\u4f7f\u7528 let\u6307\u4ee4\u8981\u597d\u8bb8\u591a\u3002<\/p>\n<pre>#!\/bin\/bash((&nbsp;a&nbsp;=&nbsp;10&nbsp;))echo&nbsp;-e&nbsp;\"inital&nbsp;value,&nbsp;a&nbsp;=&nbsp;$a\\n\"((&nbsp;a++))echo&nbsp;\"after&nbsp;a++,&nbsp;a&nbsp;=&nbsp;$a\"<\/pre>\n<p><strong>{ } \u5927\u62ec\u53f7 (Block of code)<\/strong><\/p>\n<p>\u6709\u65f6\u5019 script \u5f53\u4e2d\u4f1a\u51fa\u73b0\uff0c\u5927\u62ec\u53f7\u4e2d\u4f1a\u5939\u7740\u4e00\u6bb5\u6216\u51e0\u6bb5\u4ee5&#8221;\u5206\u53f7&#8221;\u505a\u7ed3\u5c3e\u7684\u6307\u4ee4\u6216\u53d8\u6570\u8bbe\u5b9a\u3002<\/p>\n<pre>#&nbsp;cat&nbsp;ftmp-02#!\/bin\/basha=fsh{a=inbc&nbsp;;&nbsp;echo&nbsp;-e&nbsp;\"\\n&nbsp;$a&nbsp;\\n\"}echo&nbsp;$a#.\/ftmp-02inbcinbc<\/pre>\n<p>\u8fd9\u79cd\u7528\u6cd5\u4e0e\u4e0a\u9762\u4ecb\u7ecd\u7684\u6307\u4ee4\u7fa4\u7ec4\u975e\u5e38\u76f8\u4f3c\uff0c\u4f46\u6709\u4e2a\u4e0d\u540c\u70b9\uff0c\u5b83\u5728\u5f53\u524d\u7684 shell \u6267\u884c\uff0c\u4e0d\u4f1a\u4ea7\u751f subshell\u3002<\/p>\n<p>\u5927\u62ec\u53f7\u4e5f\u88ab\u8fd0\u7528\u5728 &#8220;\u51fd\u6570&#8221; \u7684\u529f\u80fd\u4e0a\u3002\u5e7f\u4e49\u5730\u8bf4\uff0c\u5355\u7eaf\u53ea\u4f7f\u7528\u5927\u62ec\u53f7\u65f6\uff0c\u4f5c\u7528\u5c31\u50cf\u662f\u4e2a\u6ca1\u6709\u6307\u5b9a\u540d\u79f0\u7684\u51fd\u6570\u4e00\u822c\u3002\u56e0\u6b64\uff0c\u8fd9\u6837\u5199 script\u4e5f\u662f\u76f8\u5f53\u597d\u7684\u4e00\u4ef6\u4e8b\u3002\u5c24\u5176\u5bf9\u8f93\u51fa\u8f93\u5165\u7684\u91cd\u5bfc\u5411\u4e0a\uff0c\u8fd9\u4e2a\u505a\u6cd5\u53ef\u7cbe\u7b80 script \u7684\u590d\u6742\u5ea6\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u5927\u62ec\u53f7\u8fd8\u6709\u53e6\u4e00\u79cd\u7528\u6cd5\uff0c\u5982\u4e0b<\/p>\n<pre>{xx,yy,zz,...}<\/pre>\n<p>\u8fd9\u79cd\u5927\u62ec\u53f7\u7684\u7ec4\u5408\uff0c\u5e38\u7528\u5728\u5b57\u4e32\u7684\u7ec4\u5408\u4e0a\uff0c\u6765\u770b\u4e2a\u4f8b\u5b50<\/p>\n<pre>mkdir&nbsp;{userA,userB,userC}-{home,bin,data}<\/pre>\n<p>\u6211\u4eec\u5f97\u5230 userA-home, userA-bin, userA-data, userB-home, userB-bin,userB-data, userC-home, userC-bin,userC-data\uff0c\u8fd9\u51e0\u4e2a\u76ee\u5f55\u3002\u8fd9\u7ec4\u7b26\u53f7\u5728\u9002\u7528\u6027\u4e0a\u76f8\u5f53\u5e7f\u6cdb\u3002\u80fd\u52a0\u4ee5\u5584\u7528\u7684\u8bdd\uff0c\u56de\u62a5\u662f\u7cbe\u7b80\u4e0e\u6548\u7387\u3002\u50cf\u4e0b\u9762\u7684\u4f8b\u5b50<\/p>\n<pre>chown&nbsp;root&nbsp;\/usr\/{ucb\/{ex,edit},lib\/{ex?.?*,how_ex}}<\/pre>\n<p>\u5982\u679c\u4e0d\u662f\u56e0\u4e3a\u652f\u63f4\u8fd9\u79cd\u7528\u6cd5\uff0c\u6211\u4eec\u5f97\u5199\u51e0\u884c\u91cd\u590d\u51e0\u6b21\u5440<\/p>\n<p><strong>[ ] \u4e2d\u62ec\u53f7<\/strong><\/p>\n<p>\u5e38\u51fa\u73b0\u5728\u6d41\u7a0b\u63a7\u5236\u4e2d\uff0c\u626e\u6f14\u62ec\u4f4f\u5224\u65ad\u5f0f\u7684\u4f5c\u7528\u3002if [ &#8220;$?&#8221; != 0 ]thenecho &#8220;Executes error&#8221;exit1fi<\/p>\n<p>\u8fd9\u4e2a\u7b26\u53f7\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u62c5\u4efb\u7c7b\u4f3c &#8220;\u8303\u56f4&#8221; \u6216 &#8220;\u96c6\u5408&#8221; \u7684\u89d2\u8272<\/p>\n<pre>rm&nbsp;-r&nbsp;200[1234]<\/pre>\n<p>\u4e0a\u4f8b\uff0c\u4ee3\u8868\u5220\u9664 2001, 2002, 2003, 2004 \u7b49\u76ee\u5f55\u7684\u610f\u601d<\/p>\n<p><strong>[[ ]]<\/strong><\/p>\n<p>\u8fd9\u7ec4\u7b26\u53f7\u4e0e\u5148\u524d\u7684 [] \u7b26\u53f7\uff0c\u57fa\u672c\u4e0a\u4f5c\u7528\u76f8\u540c\uff0c\u4f46\u5979\u5141\u8bb8\u5728\u5176\u4e2d\u76f4\u63a5\u4f7f\u7528 || \u4e0e&amp;&amp; \u903b\u8f91\u7b49\u7b26\u53f7\u3002<\/p>\n<pre>#!\/bin\/bashread&nbsp;akif&nbsp;[[&nbsp;$ak&nbsp;&gt;&nbsp;5&nbsp;||&nbsp;$ak&lt;&nbsp;9&nbsp;]]thenecho&nbsp;$akfi<\/pre>\n<p><strong>|| \u903b\u8f91\u7b26\u53f7<\/strong><\/p>\n<p>\u8fd9\u4e2a\u4f1a\u65f6\u5e38\u770b\u5230\uff0c\u4ee3\u8868 or \u903b\u8f91\u7684\u7b26\u53f7<\/p>\n<p><strong>&amp;&amp; \u903b\u8f91\u7b26\u53f7<\/strong><\/p>\n<p>\u8fd9\u4e2a\u4e5f\u4f1a\u5e38\u770b\u5230\uff0c\u4ee3\u8868 and \u903b\u8f91\u7684\u7b26\u53f7<\/p>\n<p><strong>&amp; \u540e\u53f0\u5de5\u4f5c<\/strong><\/p>\n<p>\u5355\u4e00\u4e2a&amp; \u7b26\u53f7\uff0c\u4e14\u653e\u5728\u5b8c\u6574\u6307\u4ee4\u5217\u7684\u6700\u540e\u7aef\uff0c\u5373\u8868\u793a\u5c06\u8be5\u6307\u4ee4\u5217\u653e\u5165\u540e\u53f0\u4e2d\u5de5\u4f5c\u3002<\/p>\n<pre>tar&nbsp;cvfz&nbsp;data.tar.gz&nbsp;data&nbsp;&gt;&nbsp;\/dev\/null&amp;<\/pre>\n<p><strong>&lt;\u2026&gt; \u5355\u5b57\u8fb9\u754c<\/strong><\/p>\n<p>\u8fd9\u7ec4\u7b26\u53f7\u5728\u89c4\u5219\u8868\u8fbe\u5f0f\u4e2d\uff0c\u88ab\u5b9a\u4e49\u4e3a&#8221;\u8fb9\u754c&#8221;\u7684\u610f\u601d\u3002\u8b6c\u5982\uff0c\u5f53\u6211\u4eec\u60f3\u627e\u5bfb the \u8fd9\u4e2a\u5355\u5b57\u65f6\uff0c\u5982\u679c\u6211\u4eec\u7528<\/p>\n<pre>grep&nbsp;the&nbsp;FileA<\/pre>\n<p>\u4f60\u5c06\u4f1a\u53d1\u73b0\uff0c\u50cf there \u8fd9\u7c7b\u7684\u5355\u5b57\uff0c\u4e5f\u4f1a\u88ab\u5f53\u6210\u662f\u5339\u914d\u7684\u5355\u5b57\u3002\u56e0\u4e3a the \u6b63\u5de7\u662f there\u7684\u4e00\u90e8\u4efd\u3002\u5982\u679c\u6211\u4eec\u8981\u5fc5\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u5c31\u5f97\u52a0\u4e0a &#8220;\u8fb9\u754c&#8221; \u7684\u7b26\u53f7<\/p>\n<pre>grep&nbsp;'\\'&nbsp;FileA<\/pre>\n<ul>\n<li>\n<p>\u52a0\u53f7 (plus)<\/p>\n<\/li>\n<\/ul>\n<pre>\u5728\u8fd0\u7b97\u5f0f\u4e2d\uff0c\u5979\u7528\u6765\u8868\u793a&nbsp;\"\u52a0\u6cd5\"\u3002expr&nbsp;1&nbsp;+&nbsp;2&nbsp;+&nbsp;3\n\u6b64\u5916\u5728\u89c4\u5219\u8868\u8fbe\u5f0f\u4e2d\uff0c\u7528\u6765\u8868\u793a\"\u5f88\u591a\u4e2a\"\u7684\u524d\u9762\u5b57\u5143\u7684\u610f\u601d\u3002\n#&nbsp;grep&nbsp;'10\\+9'&nbsp;fileB109100910000910000931010009#\u8fd9\u4e2a\u7b26\u53f7\u5728\u4f7f\u7528\u65f6\uff0c\u524d\u9762\u5fc5\u987b\u52a0\u4e0aescape&nbsp;\u5b57\u5143\u3002<\/pre>\n<ul>\n<li>\n<p>\u51cf\u53f7 (dash)<\/p>\n<\/li>\n<\/ul>\n<pre>\u5728\u8fd0\u7b97\u5f0f\u4e2d\uff0c\u5979\u7528\u6765\u8868\u793a&nbsp;\"\u51cf\u6cd5\"\u3002\nexpr&nbsp;10&nbsp;-&nbsp;2\n\u6b64\u5916\u4e5f\u662f\u7cfb\u7edf\u6307\u4ee4\u7684\u9009\u9879\u7b26\u53f7\u3002\nls&nbsp;-expr&nbsp;10&nbsp;-&nbsp;2\n\u5728&nbsp;GNU&nbsp;\u6307\u4ee4\u4e2d\uff0c\u5982\u679c\u5355\u72ec\u4f7f\u7528&nbsp;-&nbsp;\u7b26\u53f7\uff0c\u4e0d\u52a0\u4efb\u4f55\u8be5\u52a0\u7684\u6587\u4ef6\u540d\u79f0\u65f6\uff0c\u4ee3\u8868\"\u6807\u51c6\u8f93\u5165\"\u7684\u610f\u601d\u3002\u8fd9\u662f&nbsp;GNU\u6307\u4ee4\u7684\u5171\u901a\u9009\u9879\u3002\u8b6c\u5982\u4e0b\u4f8b\ntar&nbsp;xpvf&nbsp;-\n\u8fd9\u91cc\u7684&nbsp;-&nbsp;\u7b26\u53f7\uff0c\u65e2\u4ee3\u8868\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u8d44\u6599\u3002\n\u4e0d\u8fc7\uff0c\u5728&nbsp;cd&nbsp;\u6307\u4ee4\u4e2d\u5219\u6bd4\u8f83\u7279\u522b\ncd&nbsp;-\n\u8fd9\u4ee3\u8868\u53d8\u66f4\u5de5\u4f5c\u76ee\u5f55\u5230\"\u4e0a\u4e00\u6b21\"\u5de5\u4f5c\u76ee\u5f55\u3002<\/pre>\n<p><strong>% \u9664\u6cd5 (Modulo)<\/strong><\/p>\n<p>\u5728\u8fd0\u7b97\u5f0f\u4e2d\uff0c\u7528\u6765\u8868\u793a &#8220;\u9664\u6cd5&#8221;\u3002<\/p>\n<pre>expr&nbsp;10&nbsp;%&nbsp;2<\/pre>\n<p>\u6b64\u5916\uff0c\u4e5f\u88ab\u8fd0\u7528\u5728\u5173\u4e8e\u53d8\u91cf\u7684\u89c4\u5219\u8868\u8fbe\u5f0f\u5f53\u4e2d\u7684\u4e0b\u5217<\/p>\n<pre>${parameter%word}${parameter%%word}<\/pre>\n<p>\u4e00\u4e2a % \u8868\u793a\u6700\u77ed\u7684 word \u5339\u914d\uff0c\u4e24\u4e2a\u8868\u793a\u6700\u957f\u7684 word \u5339\u914d\u3002<\/p>\n<p><strong>= \u7b49\u53f7 (Equals)<\/strong><\/p>\n<p>\u5e38\u5728\u8bbe\u5b9a\u53d8\u6570\u65f6\u770b\u5230\u7684\u7b26\u53f7\u3002<\/p>\n<pre>vara=123echo&nbsp;\"&nbsp;vara&nbsp;=&nbsp;$vara\"<\/pre>\n<p>\u6216\u8005\u50cf\u662f PATH \u7684\u8bbe\u5b9a\uff0c\u751a\u81f3\u5e94\u7528\u5728\u8fd0\u7b97\u6216\u5224\u65ad\u5f0f\u7b49\u6b64\u7c7b\u7528\u9014\u4e0a\u3002<\/p>\n<p><strong>== \u7b49\u53f7 (Equals)<\/strong><\/p>\n<p>\u5e38\u5728\u6761\u4ef6\u5224\u65ad\u5f0f\u4e2d\u770b\u5230\uff0c\u4ee3\u8868 &#8220;\u7b49\u4e8e&#8221; \u7684\u610f\u601d\u3002<\/p>\n<pre>if&nbsp;[&nbsp;$vara&nbsp;==&nbsp;$varb&nbsp;]...\u4e0b\u7565<\/pre>\n<p><strong>!= \u4e0d\u7b49\u4e8e<\/strong><\/p>\n<p>\u5e38\u5728\u6761\u4ef6\u5224\u65ad\u5f0f\u4e2d\u770b\u5230\uff0c\u4ee3\u8868 &#8220;\u4e0d\u7b49\u4e8e&#8221; \u7684\u610f\u601d\u3002<\/p>\n<pre>if&nbsp;[&nbsp;$vara&nbsp;!=&nbsp;$varb&nbsp;]...\u4e0b\u7565<\/pre>\n<p><strong>^<\/strong><\/p>\n<p>\u8fd9\u4e2a\u7b26\u53f7\u5728\u89c4\u5219\u8868\u8fbe\u5f0f\u4e2d\uff0c\u4ee3\u8868\u884c\u7684 &#8220;\u5f00\u5934&#8221; \u4f4d\u7f6e\uff0c\u5728[]\u4e2d\u4e5f\u4e0e&#8221;!&#8221;(\u53f9\u53f7)\u4e00\u6837\u8868\u793a\u201c\u975e\u201d<\/p>\n<p><strong>\u8f93\u51fa\/\u8f93\u5165\u91cd\u5bfc\u5411<\/strong><\/p>\n<blockquote>\n<p>&gt; &nbsp; &nbsp; &nbsp;&gt;&gt; &nbsp; &lt; &nbsp; &lt;&lt; &nbsp; :&gt; &nbsp; &amp;&gt; &nbsp; 2&amp;&gt; &nbsp; 2&lt;&gt;&gt;&amp; &nbsp; &gt;&amp;2<\/p>\n<\/blockquote>\n<p>\u6587\u4ef6\u63cf\u8ff0\u7b26(File Descriptor)\uff0c\u7528\u4e00\u4e2a\u6570\u5b57\uff08\u901a\u5e38\u4e3a0-9\uff09\u6765\u8868\u793a\u4e00\u4e2a\u6587\u4ef6\u3002<\/p>\n<p>\u5e38\u7528\u7684\u6587\u4ef6\u63cf\u8ff0\u7b26\u5982\u4e0b\uff1a<\/p>\n<pre>\u6587\u4ef6\u63cf\u8ff0\u7b26&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u540d\u79f0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5e38\u7528\u7f29\u5199&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u9ed8\u8ba4\u503c\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6807\u51c6\u8f93\u5165&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stdin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u952e\u76d8\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6807\u51c6\u8f93\u51fa&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stdout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5c4f\u5e55\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u6807\u51c6\u9519\u8bef\u8f93\u51fa&nbsp;&nbsp;&nbsp;stderr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\u5c4f\u5e55<\/pre>\n<p>\u6211\u4eec\u5728\u7b80\u5355\u5730\u7528&lt;\u6216&gt;\u65f6\uff0c\u76f8\u5f53\u4e8e\u4f7f\u7528 0&lt; \u6216 1&gt;\uff08\u4e0b\u9762\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\uff09\u3002<\/p>\n<ul>\n<li>\n<p>* cmd &gt; file<\/p>\n<p>\u628acmd\u547d\u4ee4\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u6587\u4ef6file\u4e2d\u3002\u5982\u679cfile\u5df2\u7ecf\u5b58\u5728\uff0c\u5219\u6e05\u7a7a\u539f\u6709\u6587\u4ef6\uff0c\u4f7f\u7528bash\u7684noclobber\u9009\u9879\u53ef\u4ee5\u9632\u6b62\u590d\u76d6\u539f\u6709\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>* cmd &gt;&gt; file<\/p>\n<p>\u628acmd\u547d\u4ee4\u7684\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u6587\u4ef6file\u4e2d\uff0c\u5982\u679cfile\u5df2\u7ecf\u5b58\u5728\uff0c\u5219\u628a\u4fe1\u606f\u52a0\u5728\u539f\u6709\u6587\u4ef6\u5f8c\u9762\u3002<\/p>\n<\/li>\n<li>\n<p>* cmd &lt; file<\/p>\n<p>\u4f7fcmd\u547d\u4ee4\u4ecefile\u8bfb\u5165<\/p>\n<\/li>\n<li>\n<p>* cmd &lt;&lt; text<\/p>\n<p>\u4ece\u547d\u4ee4\u884c\u8bfb\u53d6\u8f93\u5165\uff0c\u76f4\u5230\u4e00\u4e2a\u4e0etext\u76f8\u540c\u7684\u884c\u7ed3\u675f\u3002\u9664\u975e\u4f7f\u7528\u5f15\u53f7\u628a\u8f93\u5165\u62ec\u8d77\u6765\uff0c\u6b64\u6a21\u5f0f\u5c06\u5bf9\u8f93\u5165\u5185\u5bb9\u8fdb\u884cshell\u53d8\u91cf\u66ff\u6362\u3002\u5982\u679c\u4f7f\u7528&lt;&lt;- \uff0c\u5219\u4f1a\u5ffd\u7565\u63a5\u4e0b\u6765\u8f93\u5165\u884c\u9996\u7684tab\uff0c\u7ed3\u675f\u884c\u4e5f\u53ef\u4ee5\u662f\u4e00\u5806tab\u518d\u52a0\u4e0a\u4e00\u4e2a\u4e0etext\u76f8\u540c\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u53c2\u8003\u5f8c\u9762\u7684\u4f8b\u5b50\u3002<\/p>\n<\/li>\n<li>\n<p>* cmd &lt;&lt;&lt; word<\/p>\n<p>\u628aword\uff08\u800c\u4e0d\u662f\u6587\u4ef6word\uff09\u548c\u5f8c\u9762\u7684\u6362\u884c\u4f5c\u4e3a\u8f93\u5165\u63d0\u4f9b\u7ed9cmd\u3002<\/p>\n<\/li>\n<li>\n<p>* cmd &lt;&gt; file<\/p>\n<p>\u4ee5\u8bfb\u5199\u6a21\u5f0f\u628a\u6587\u4ef6file\u91cd\u5b9a\u5411\u5230\u8f93\u5165\uff0c\u6587\u4ef6file\u4e0d\u4f1a\u88ab\u7834\u574f\u3002\u4ec5\u5f53\u5e94\u7528\u7a0b\u5e8f\u5229\u7528\u4e86\u8fd9\u4e00\u7279\u6027\u65f6\uff0c\u5b83\u624d\u662f\u6709\u610f\u4e49\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>* cmd &gt;| file<\/p>\n<p>\u529f\u80fd\u540c&gt;\uff0c\u4f46\u5373\u4fbf\u5728\u8bbe\u7f6e\u4e86noclobber\u65f6\u4e5f\u4f1a\u590d\u76d6file\u6587\u4ef6\uff0c\u6ce8\u610f\u7528\u7684\u662f|\u800c\u975e\u4e00\u4e9b\u4e66\u4e2d\u8bf4\u7684!\uff0c\u76ee\u524d\u4ec5\u5728csh\u4e2d\u4ecd\u6cbf\u7528&gt;!\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/p>\n<\/li>\n<li>\n<p>: &gt; filename &nbsp; &nbsp; &nbsp;\u628a\u6587\u4ef6&#8221;filename&#8221;\u622a\u65ad\u4e3a0\u957f\u5ea6.# \u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728, \u90a3\u4e48\u5c31\u521b\u5efa\u4e00\u4e2a0\u957f\u5ea6\u7684\u6587\u4ef6(\u4e0e&#8217;touch&#8217;\u7684\u6548\u679c\u76f8\u540c).<\/p>\n<\/li>\n<li>\n<p>cmd &gt;&amp;n \u628a\u8f93\u51fa\u9001\u5230\u6587\u4ef6\u63cf\u8ff0\u7b26n<\/p>\n<\/li>\n<li>\n<p>cmd m&gt;&amp;n \u628a\u8f93\u51fa \u5230\u6587\u4ef6\u7b26m\u7684\u4fe1\u606f\u91cd\u5b9a\u5411\u5230\u6587\u4ef6\u63cf\u8ff0\u7b26n<\/p>\n<\/li>\n<li>\n<p>cmd &gt;&amp;- \u5173\u95ed\u6807\u51c6\u8f93\u51fa<\/p>\n<\/li>\n<li>\n<p>cmd &lt;&amp;n \u8f93\u5165\u6765\u81ea\u6587\u4ef6\u63cf\u8ff0\u7b26n<\/p>\n<\/li>\n<li>\n<p>cmd m&lt;&amp;n m\u6765\u81ea\u6587\u4ef6\u63cf\u8ff0\u5404\u4e2an<\/p>\n<\/li>\n<li>\n<p>cmd &lt;&amp;- \u5173\u95ed\u6807\u51c6\u8f93\u5165<\/p>\n<\/li>\n<li>\n<p>cmd &lt;&amp;n- \u79fb\u52a8\u8f93\u5165\u6587\u4ef6\u63cf\u8ff0\u7b26n\u800c\u975e\u590d\u5236\u5b83\u3002\uff08\u9700\u8981\u89e3\u91ca\uff09<\/p>\n<\/li>\n<li>\n<p>cmd &gt;&amp;n- \u79fb\u52a8\u8f93\u51fa\u6587\u4ef6\u63cf\u8ff0\u7b26 n\u800c\u975e\u590d\u5236\u5b83\u3002\uff08\u9700\u8981\u89e3\u91ca\uff09<\/p>\n<\/li>\n<\/ul>\n<p>\u6ce8\u610f\uff1a &gt;&amp;\u5b9e\u9645\u4e0a\u590d\u5236\u4e86\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u8fd9\u4f7f\u5f97cmd &gt; file 2&gt;&amp;1\u4e0ecmd 2&gt;&amp;1 &gt;file\u7684\u6548\u679c\u4e0d\u4e00\u6837\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300alinux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>linux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48 \u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300alinux\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\u53ca\u542b\u4e49\u662f\u4ec0\u4e48\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002 linux\u7684\u7279\u6b8a\u5b57\u7b26\uff1a1\u3001\u201c#\u201d\u6ce8\u91ca\u5b57\u7b26\uff1b2\u3001\u201c~\u201d\uff0c\u4ee3\u8868\u7528\u6237\u7684home\u76ee\u5f55\uff1b3\u3001\u201c;\u201d\uff0c\u662f\u62c5\u4efb\u201c\u8fde\u7eed\u6307\u4ee4\u201d\u529f\u80fd\u7684\u7b26\u53f7\uff1b4\u3001\u201c\/\u201d\uff0c\u8def\u5f84\u76ee\u5f55\u5206\u9694\u7b26\uff1b5\u3001\u201c\\\u201d\uff0c\u8f6c\u4e49\u7b26\uff1b6\u3001\u201c|\u201d\uff0c\u7ba1\u9053\u7b26\uff1b7\u3001\u201c.\u201d\uff0c\u4ee3\u8868\u5f53\u524d\u76ee\u5f55\uff1b8\u3001\u201c..\u201d\uff0c\u4ee3\u8868\u7236\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u5f53\u524d\u76ee\u5f55\u7684\u4e0a\u4e00\u7ea7\u76ee\u5f55\uff1b9\u3001\u201c?\u201d\uff0c\u6307\u7684\u662f\u5355\u5b57\u7b26\u901a\u914d\u7b26\uff0c\u4ee3\u8868\u6587\u4ef6\u540d\u4e2d\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u7684\u5339\u914d\uff1b10\u3001\u201c*\u201d\uff0c\u4ee3\u8868\u4efb\u610f\u5b57\u7b26\u5e8f\u5217\uff0c\u5339\u914d\u4efb\u610f\u5b57\u7b26\u7b49\u3002 linux\u7279\u6b8a\u7b26\u53f7\u4f7f\u7528\u53ca\u542b\u4e49 #\uff1a \u4ee5 # \u5f00\u5934\uff0c\u4ee3\u8868\u8fd9\u53e5\u8bdd\u662f\u6ce8\u91ca\u3002 #\uff01\/bin\/bash&nbsp;\u5e38\u51fa\u73b0\u5728\u547d\u4ee4\u4e4b\u524d\uff0c\u6216\u8005\u547d\u4ee4\u4e4b\u540e\uff0c\u540e\u9762\u662f\u6ce8\u91ca\u6587\u5b57\uff0c\u4e0d\u4f1a\u88ab\u6267\u884c #\u5f53\u8f93\u5165\u7684\u547d\u4ee4\u4e0d\u60f3\u88ab\u6267\u884c\u65f6\u8f93\u5165\uff08#\uff09\u5c31\u884c\u4e86 #This&nbsp;line&nbsp;is&nbsp;comments.\uff08\u8fd9\u662f\u4e00\u884c\u6ce8\u91ca\uff09 \u867d\u7136\u4e0a\u9762\u90a3\u6bb5\u8bdd\u5c31\u88ab\u5ffd\u7565\u4e86\uff0c\u4f46\u5b83\u8fd8\u662f\u4f1a\u6dfb\u52a0\u5230\u60a8\u7684\u547d\u4ee4\u5386\u53f2\u8bb0\u5f55\u4e2d\u3002 \u66f4\u5389\u5bb3\u7684\u505a\u6cd5\u5982\u4e0b\uff1a \u5148\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\u5e76\u7ed9\u5b83\u8d4b\u503c\u5b57\u7b26\u4e32 \u201camazing alvin\u201d this_string=&#8221;amazing&nbsp;alvin&#8221; ${this_string#amazing} \u8fd4\u56de\u7684\u662f\u88ab\u6ce8\u91ca\u6389 amazing \u7684 this_string \u5b57\u7b26\u4e32\u53d8\u91cf\uff0c\u53ef\u4ee5 echo \u8f93\u51fa\u770b\u4e0b\u7ed3\u679c\uff1a echo&nbsp;awsome&nbsp;${this_string#amazing} amazing \u53ea\u662f\u88ab\u6ce8\u91ca\u6389\u800c\u5df2\uff0c\u5b83\u5e76\u672a\u88ab\u5220\u9664\uff0c\u53bb\u6389\u6ce8\u91ca\u5b83\u5c31\u56de\u6765\u4e86\uff1a echo&nbsp;$this_string ~ ~ \u4ee3\u8868\u7528\u6237\u7684home\u76ee\u5f55\uff0c\u6307\u7684\u662f\u4e3b\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u7528\u6237\u7684\u4e2a\u4eba\u76ee\u5f55\uff0c\u65e0\u8bba\u4f60\u8eab\u5728\u4f55\u65b9\uff0c\u8f93\u5165 cd ~ \u5b83\u5c06\u5e26\u4f60\u56de\u5bb6\uff01 cd&nbsp;~ \u66f4\u9ad8\u7aef\u7684\u73a9\u6cd5\u5c31\u662f\u5728\u5b83\u540e\u9762\u52a0\u4e0a\u5177\u4f53\u7684\u8def\u5f84\uff0c\u76f4\u63a5\u5b9a\u4f4d\u5230\u5bb6\u76ee\u5f55\u4e2d\u7684\u6307\u5b9a\u4f4d\u7f6e\uff0c\u662f\u4e0d\u662f\u5f88\u65b9\u4fbf\u5462\uff1f cd&nbsp;~\/work\/archive \uff1b\u5206\u53f7 \u5728 shell \u4e2d\uff0c\u62c5\u4efb&#8221;\u8fde\u7eed\u6307\u4ee4&#8221;\u529f\u80fd\u7684\u7b26\u53f7\u5c31\u662f&#8221;\u5206\u53f7&#8221;\u3002 \u8fd9\u8ddf\u6211\u4eec\u65e5\u5e38\u4f7f\u7528\u7684 &#8220;;&#8221; \u5dee\u4e0d\u591a\uff0c\u5c31\u4e0d\u7ec6\u8bf4\u4e86\uff0c\u4e3b\u8981\u662f\u7528\u6765\u5206\u9694\u547d\u4ee4\u7684\u3002 ls&nbsp;&gt;&nbsp;count.txt;&nbsp;wc&nbsp;-l&nbsp;count.txt;&nbsp;rm&nbsp;count.txt \u8fd9\u91cc\u6ce8\u610f\uff0c\u7528 ; \u5206\u9694\u547d\u4ee4\u65f6\uff0c\u5373\u4f7f\u7b2c\u4e00\u4e2a\u547d\u4ee4\u5931\u8d25\uff0c\u7b2c\u4e8c\u4e2a\u547d\u4ee4\u4e5f\u4f1a\u8fd0\u884c\uff0c\u5373\u4f7f\u7b2c\u4e8c\u4e2a\u547d\u4ee4\u5931\u8d25\uff0c\u7b2c\u4e09\u4e2a\u547d\u4ee4\u4e5f\u4f1a\u8fd0\u884c\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002 \u5982\u679c\u8981\u5728\u4e00\u4e2a\u547d\u4ee4\u5931\u8d25\u7684\u60c5\u51b5\u4e0b\u5c31\u505c\u6b62\uff0c\u8bf7\u4f7f\u7528 &#8220;&amp;&amp;&#8221; \uff0c\u5982\u4e0b\uff1a cd&nbsp;.\/doesntexist&nbsp;&amp;&amp;&nbsp;cp&nbsp;~\/Documents\/reports\/*&nbsp;. \uff1b\uff1b\u8fde\u7eed\u5206\u53f7 (Terminator) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-51979","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/51979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=51979"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/51979\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=51979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=51979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=51979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}