{"id":1498,"date":"2022-05-27T09:19:31","date_gmt":"2022-05-27T01:19:31","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=1498"},"modified":"2022-05-27T12:52:44","modified_gmt":"2022-05-27T04:52:44","slug":"chapter-04","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/chapter-04.html","title":{"rendered":"\u7b2c4\u7ae0 Vim\u7f16\u8f91\u5668\u4e0eShell\u547d\u4ee4\u811a\u672c\u3002"},"content":{"rendered":"

👇\u672c\u7ae0\u8282\u5185\u5bb9\u5df2\u66f4\u65b0\uff0c\u8bf7\u5728\u7ebf\u9605\u8bfb\u6700\u65b0RHEL 8\u7248\u672c\u4e66\u7c4d 👇<\/span><\/strong><\/span><\/p>\n

https:\/\/lrxjmw.cn\/basic-learning-04.html<\/span><\/strong><\/span><\/b><\/p>\n

*\u4ea6\u53ef\u5c31\u8fd1\u5728\u65b0\u534e\u4e66\u5e97\u8d2d\u4e70*<\/b><\/span><\/p>\n

\u7ae0\u8282\u7b80\u8ff0<\/strong>:<\/span><\/p>\n

\u672c\u7ae0\u9996\u5148\u8bb2\u89e3\u5982\u4f55\u4f7f\u7528Vim\u7f16\u8f91\u5668\u6765\u7f16\u5199\u3001\u4fee\u6539\u6587\u6863\uff0c\u7136\u540e\u901a\u8fc7\u9010\u4e2a\u914d\u7f6e\u4e3b\u673a\u540d\u79f0\u3001\u7cfb\u7edf\u7f51\u5361\u4ee5\u53caYum\u8f6f\u4ef6\u4ed3\u5e93\u53c2\u6570\u6587\u4ef6\u7b49\u5b9e\u9a8c\uff0c\u5e2e\u52a9\u8bfb\u8005\u52a0\u6df1Vim\u7f16\u8f91\u5668\u4e2d\u8bf8\u591a\u547d\u4ee4\u3001\u5feb\u6377\u952e\u3001\u6a21\u5f0f\u5207\u6362\u65b9\u6cd5\u7684\u7406\u89e3\u3002\u7136\u540e\u628a\u524d\u9762\u7ae0\u8282\u4e2d\u8bb2\u89e3\u7684Linux\u547d\u4ee4<\/a>\u3001\u547d\u4ee4\u8bed\u6cd5\u4e0eShell\u811a\u672c\u4e2d\u7684\u5404\u79cd\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u901a\u8fc7Vim\u7f16\u8f91\u5668\u5199\u5230Shell\u811a\u672c\u4e2d\u7ed3\u5408\u5230\u4e00\u8d77\uff0c\u5b9e\u73b0\u6700\u7ec8\u80fd\u591f\u81ea\u52a8\u5316\u5de5\u4f5c\u7684\u811a\u672c\u6587\u4ef6\u3002\u672c\u7ae0\u6700\u540e\u6f14\u793a\u4e86\u600e\u6837\u901a\u8fc7at\u547d\u4ee4\u4e0ecrond\u8ba1\u5212\u4efb\u52a1\u670d\u52a1\u6765\u5206\u522b\u5b9e\u73b0\u4e00\u6b21\u6027\u7684\u7cfb\u7edf\u4efb\u52a1\u8bbe\u7f6e\u548c\u957f\u671f\u6027\u7684\u7cfb\u7edf\u4efb\u52a1\u8bbe\u7f6e\uff0c\u4ece\u800c\u8ba9\u65e5\u5e38\u7684\u5de5\u4f5c\u66f4\u52a0\u9ad8\u6548\uff0c\u66f4\u81ea\u52a8\u5316\u3002<\/p>\n

4.1 Vim\u6587\u672c\u7f16\u8f91\u5668<\/strong><\/span><\/h5>\n

\u6bcf\u5f53\u5728\u8bb2\u8bfe\u65f6\u9047\u5230\u9700\u8981\u8ba9\u5b66\u751f\u8bb0\u4f4f\u7684\u77e5\u8bc6\u70b9\u65f6\uff0c\u4e3a\u4e86\u80fd\u8ba9\u4ed6\u4eec\u6253\u8d77\u7cbe\u795e\u6765\uff0c\u6211\u90fd\u4f1a\u7a81\u7136\u63d0\u9ad8\u55d3\u95e8\uff0c\u56e0\u6b64\u6709\u53e5\u8bdd\u4ed6\u4eec\u8bb0\u5f97\u5c24\u5176\u6df1\u523b\uff1a\u201c\u5728Linux\u7cfb\u7edf\u4e2d\u4e00\u5207\u90fd\u662f\u6587\u4ef6\uff0c\u800c\u914d\u7f6e\u4e00\u4e2a\u670d\u52a1\u5c31\u662f\u5728\u4fee\u6539\u5176\u914d\u7f6e\u6587\u4ef6\u7684\u53c2\u6570\u201d\u3002\u800c\u4e14\u5728\u65e5\u5e38\u5de5\u4f5c\u4e2d\u5927\u5bb6\u4e5f\u80af\u5b9a\u514d\u4e0d\u4e86\u8981\u7f16\u5199\u6587\u6863\uff0c\u8fd9\u4e9b\u5de5\u4f5c\u90fd\u662f\u901a\u8fc7\u6587\u672c\u7f16\u8f91\u5668\u6765\u5b8c\u6210\u7684\u3002\u5218\u9044\u8001\u5e08\u5199\u4f5c\u672c\u4e66\u7684\u76ee\u7684\u662f\u8ba9\u8bfb\u8005\u5207\u5b9e\u638c\u63e1Linux\u7cfb\u7edf\u7684\u8fd0\u7ef4\u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u4ec5\u4ec5\u505c\u7559\u5728\u201c\u4f1a\u7528\u67d0\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u201d\u7684\u5c42\u9762\u4e0a\uff0c\u6240\u4ee5\u6211\u4eec\u8fd9\u91cc\u9009\u62e9\u4f7f\u7528Vim\u6587\u672c\u7f16\u8f91\u5668\uff0c\u5b83\u9ed8\u8ba4\u4f1a\u5b89\u88c5\u5728\u5f53\u524d\u6240\u6709\u7684Linux\u64cd\u4f5c\u7cfb\u7edf\u4e0a\uff0c\u662f\u4e00\u6b3e\u8d85\u68d2\u7684\u6587\u672c\u7f16\u8f91\u5668\u3002<\/p>\n

Vim\u4e4b\u6240\u4ee5\u80fd\u5f97\u5230\u5e7f\u5927\u5382\u5546\u4e0e\u7528\u6237\u7684\u8ba4\u53ef\uff0c\u539f\u56e0\u5728\u4e8eVim\u7f16\u8f91\u5668\u4e2d\u8bbe\u7f6e\u4e86\u4e09\u79cd\u6a21\u5f0f\u2014\u547d\u4ee4\u6a21\u5f0f\u3001\u672b\u884c\u6a21\u5f0f\u548c\u7f16\u8f91\u6a21\u5f0f\uff0c\u6bcf\u79cd\u6a21\u5f0f\u5206\u522b\u53c8\u652f\u6301\u591a\u79cd\u4e0d\u540c\u7684\u547d\u4ee4\u5feb\u6377\u952e\uff0c\u8fd9\u5927\u5927\u63d0\u9ad8\u4e86\u5de5\u4f5c\u6548\u7387\uff0c\u800c\u4e14\u7528\u6237\u5728\u4e60\u60ef\u4e4b\u540e\u4e5f\u4f1a\u89c9\u5f97\u76f8\u5f53\u987a\u624b\u3002\u8981\u60f3\u9ad8\u6548\u7387\u5730\u64cd\u4f5c\u6587\u672c\uff0c\u5c31\u5fc5\u987b\u5148\u641e\u6e05\u8fd9\u4e09\u79cd\u6a21\u5f0f\u7684\u64cd\u4f5c\u533a\u522b\u4ee5\u53ca\u6a21\u5f0f\u4e4b\u95f4\u7684\u5207\u6362\u65b9\u6cd5\uff08\u89c1\u56fe4-1\uff09\u3002<\/p>\n

\u547d\u4ee4\u6a21\u5f0f\uff1a\u63a7\u5236\u5149\u6807\u79fb\u52a8\uff0c\u53ef\u5bf9\u6587\u672c\u8fdb\u884c\u590d\u5236\u3001\u7c98\u8d34\u3001\u5220\u9664\u548c\u67e5\u627e\u7b49\u5de5\u4f5c\u3002<\/p>\n

\u8f93\u5165\u6a21\u5f0f\uff1a\u6b63\u5e38\u7684\u6587\u672c\u5f55\u5165\u3002<\/p>\n

\u672b\u884c\u6a21\u5f0f\uff1a\u4fdd\u5b58\u6216\u9000\u51fa\u6587\u6863\uff0c\u4ee5\u53ca\u8bbe\u7f6e\u7f16\u8f91\u73af\u5883\u3002<\/p><\/blockquote>\n

\"vim\u4e0d\u540c\u6a21\u5f0f\u95f4\u7684\u5207\u6362\"<\/p>\n

\u56fe4-1\u00a0 Vim\u7f16\u8f91\u5668\u6a21\u5f0f\u7684\u5207\u6362\u65b9\u6cd5<\/p>\n

\u5728\u6bcf\u6b21\u8fd0\u884cVim\u7f16\u8f91\u5668\u65f6\uff0c\u9ed8\u8ba4\u8fdb\u5165\u547d\u4ee4\u6a21\u5f0f\uff0c\u6b64\u65f6\u9700\u8981\u5148\u5207\u6362\u5230\u8f93\u5165\u6a21\u5f0f\u540e\u518d\u8fdb\u884c\u6587\u6863\u7f16\u5199\u5de5\u4f5c\uff0c\u800c\u6bcf\u6b21\u5728\u7f16\u5199\u5b8c\u6587\u6863\u540e\u9700\u8981\u5148\u8fd4\u56de\u547d\u4ee4\u6a21\u5f0f\uff0c\u7136\u540e\u518d\u8fdb\u5165\u672b\u884c\u6a21\u5f0f\uff0c\u6267\u884c\u6587\u6863\u7684\u4fdd\u5b58\u6216\u9000\u51fa\u64cd\u4f5c\u3002\u5728Vim\u4e2d\uff0c\u65e0\u6cd5\u76f4\u63a5\u4ece\u8f93\u5165\u6a21\u5f0f\u5207\u6362\u5230\u672b\u884c\u6a21\u5f0f\u3002Vim\u7f16\u8f91\u5668\u4e2d\u5185\u7f6e\u7684\u547d\u4ee4\u6709\u6210\u767e\u4e0a\u5343\u79cd\u7528\u6cd5\uff0c\u4e3a\u4e86\u80fd\u591f\u5e2e\u52a9\u8bfb\u8005\u66f4\u5feb\u5730\u638c\u63e1Vim\u7f16\u8f91\u5668\uff0c\u88684-1\u603b\u7ed3\u4e86\u5728\u547d\u4ee4\u6a21\u5f0f\u4e2d\u6700\u5e38\u7528\u7684\u4e00\u4e9b\u547d\u4ee4\u3002<\/p>\n

\u88684-1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Vim\u4e2d\u5e38\u7528\u7684\u547d\u4ee4<\/p>\n\n\n\n\n\n\n\n\n\n\n\n
\u547d\u4ee4<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
dd<\/td>\n\u5220\u9664\uff08\u526a\u5207\uff09\u5149\u6807\u6240\u5728\u6574\u884c<\/td>\n<\/tr>\n
5dd<\/td>\n\u5220\u9664\uff08\u526a\u5207\uff09\u4ece\u5149\u6807\u5904\u5f00\u59cb\u76845\u884c<\/td>\n<\/tr>\n
yy<\/td>\n\u590d\u5236\u5149\u6807\u6240\u5728\u6574\u884c<\/td>\n<\/tr>\n
5yy<\/td>\n\u590d\u5236\u4ece\u5149\u6807\u5904\u5f00\u59cb\u76845\u884c<\/td>\n<\/tr>\n
n<\/td>\n\u663e\u793a\u641c\u7d22\u547d\u4ee4\u5b9a\u4f4d\u5230\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n
N<\/td>\n\u663e\u793a\u641c\u7d22\u547d\u4ee4\u5b9a\u4f4d\u5230\u7684\u4e0a\u4e00\u4e2a\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n
u<\/td>\n\u64a4\u9500\u4e0a\u4e00\u6b65\u7684\u64cd\u4f5c<\/td>\n<\/tr>\n
p<\/td>\n\u5c06\u4e4b\u524d\u5220\u9664\uff08dd\uff09\u6216\u590d\u5236\uff08yy\uff09\u8fc7\u7684\u6570\u636e\u7c98\u8d34\u5230\u5149\u6807\u540e\u9762<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

\u672b\u884c\u6a21\u5f0f\u4e3b\u8981\u7528\u4e8e\u4fdd\u5b58\u6216\u9000\u51fa\u6587\u4ef6\uff0c\u4ee5\u53ca\u8bbe\u7f6eVim\u7f16\u8f91\u5668\u7684\u5de5\u4f5c\u73af\u5883\uff0c\u8fd8\u53ef\u4ee5\u8ba9\u7528\u6237\u6267\u884c\u5916\u90e8\u7684Linux\u547d\u4ee4<\/a>\u6216\u8df3\u8f6c\u5230\u6240\u7f16\u5199\u6587\u6863\u7684\u7279\u5b9a\u884c\u6570\u3002\u8981\u60f3\u5207\u6362\u5230\u672b\u884c\u6a21\u5f0f\uff0c\u5728\u547d\u4ee4\u6a21\u5f0f\u4e2d\u8f93\u5165\u4e00\u4e2a\u5192\u53f7\u5c31\u53ef\u4ee5\u4e86\u3002\u672b\u884c\u6a21\u5f0f\u4e2d\u53ef\u7528\u7684\u547d\u4ee4\u5982\u88684-2\u6240\u793a\u3002<\/p>\n

\u88684-2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u672b\u884c\u6a21\u5f0f\u4e2d\u53ef\u7528\u7684\u547d\u4ee4<\/p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\u547d\u4ee4<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
:w<\/td>\n\u4fdd\u5b58<\/td>\n<\/tr>\n
:q<\/td>\n\u9000\u51fa<\/td>\n<\/tr>\n
:q!<\/td>\n\u5f3a\u5236\u9000\u51fa\uff08\u653e\u5f03\u5bf9\u6587\u6863\u7684\u4fee\u6539\u5185\u5bb9\uff09<\/td>\n<\/tr>\n
:wq!<\/td>\n\u5f3a\u5236\u4fdd\u5b58\u9000\u51fa<\/td>\n<\/tr>\n
:set nu<\/td>\n\u663e\u793a\u884c\u53f7<\/td>\n<\/tr>\n
:set nonu<\/td>\n\u4e0d\u663e\u793a\u884c\u53f7<\/td>\n<\/tr>\n
:\u547d\u4ee4<\/td>\n\u6267\u884c\u8be5\u547d\u4ee4<\/td>\n<\/tr>\n
:\u6574\u6570<\/td>\n\u8df3\u8f6c\u5230\u8be5\u884c<\/td>\n<\/tr>\n
:s\/one\/two<\/td>\n\u5c06\u5f53\u524d\u5149\u6807\u6240\u5728\u884c\u7684\u7b2c\u4e00\u4e2aone\u66ff\u6362\u6210two<\/td>\n<\/tr>\n
:s\/one\/two\/g<\/td>\n\u5c06\u5f53\u524d\u5149\u6807\u6240\u5728\u884c\u7684\u6240\u6709one\u66ff\u6362\u6210two<\/td>\n<\/tr>\n
:%s\/one\/two\/g<\/td>\n\u5c06\u5168\u6587\u4e2d\u7684\u6240\u6709one\u66ff\u6362\u6210two<\/td>\n<\/tr>\n
?\u5b57\u7b26\u4e32<\/td>\n\u5728\u6587\u672c\u4e2d\u4ece\u4e0b\u81f3\u4e0a\u641c\u7d22\u8be5\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n
\/\u5b57\u7b26\u4e32<\/td>\n\u5728\u6587\u672c\u4e2d\u4ece\u4e0a\u81f3\u4e0b\u641c\u7d22\u8be5\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

4.1.1 \u7f16\u5199\u7b80\u5355\u6587\u6863<\/strong><\/span><\/h6>\n

\u76ee\u524d\u4e3a\u6b62\uff0c\u5927\u5bb6\u5df2\u7ecf\u5177\u5907\u4e86\u5728Linux\u7cfb\u7edf\u4e2d\u7f16\u5199\u6587\u6863\u7684\u7406\u8bba\u57fa\u7840\u4e86\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u4e00\u8d77\u52a8\u624b\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u811a\u672c\u6587\u6863\u3002\u5218\u9044\u8001\u5e08\u4f1a\u5c3d\u529b\u628a\u6240\u6709\u64cd\u4f5c\u6b65\u9aa4\u548c\u6309\u952e\u8fc7\u7a0b\u90fd\u6807\u6ce8\u51fa\u6765\uff0c\u5982\u679c\u5fd8\u8bb0\u4e86\u67d0\u4e9b\u5feb\u6377\u952e\u547d\u4ee4\u7684\u4f5c\u7528\uff0c\u53ef\u4ee5\u518d\u8fd4\u56de\u524d\u6587\u8fdb\u884c\u590d\u4e60\u3002<\/p>\n

\u7f16\u5199\u811a\u672c\u6587\u6863\u7684\u7b2c1\u6b65\u5c31\u662f\u7ed9\u6587\u6863\u53d6\u4e2a\u540d\u5b57\uff0c\u8fd9\u91cc\u5c06\u5176\u547d\u540d\u4e3apractice.txt\u3002\u5982\u679c\u5b58\u5728\u8be5\u6587\u6863\uff0c\u5219\u662f\u6253\u5f00\u5b83\u3002\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u662f\u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u7684\u8f93\u5165\u6587\u4ef6\uff0c\u5982\u56fe4-2\u6240\u793a\u3002<\/p>\n

\"\u7b2c1\u6b65\uff1a\u521b\u5efa\u6587\u6863\u3002\"<\/p>\n

\u56fe4-2\u00a0 \u5c1d\u8bd5\u7f16\u5199\u811a\u672c\u6587\u6863<\/p>\n

\u6253\u5f00practice.txt\u6587\u6863\u540e\uff0c\u9ed8\u8ba4\u8fdb\u5165\u7684\u662fVim\u7f16\u8f91\u5668\u7684\u547d\u4ee4\u6a21\u5f0f\u3002\u6b64\u65f6\u53ea\u80fd\u6267\u884c\u8be5\u6a21\u5f0f\u4e0b\u7684\u547d\u4ee4\uff0c\u800c\u4e0d\u80fd\u968f\u610f\u8f93\u5165\u6587\u672c\u5185\u5bb9\uff0c\u6211\u4eec\u9700\u8981\u5207\u6362\u5230\u8f93\u5165\u6a21\u5f0f\u624d\u53ef\u4ee5\u7f16\u5199\u6587\u6863\u3002<\/p>\n

\u5728\u56fe4-1\u4e2d\u63d0\u5230\uff0c\u53ef\u4ee5\u5206\u522b\u4f7f\u7528a\u3001i\u3001o\u4e09\u4e2a\u952e\u4ece\u547d\u4ee4\u6a21\u5f0f\u5207\u6362\u5230\u8f93\u5165\u6a21\u5f0f\u3002\u5176\u4e2d\uff0ca\u952e\u4e0ei\u952e\u5206\u522b\u662f\u5728\u5149\u6807\u540e\u9762\u4e00\u4f4d\u548c\u5149\u6807\u5f53\u524d\u4f4d\u7f6e\u5207\u6362\u5230\u8f93\u5165\u6a21\u5f0f\uff0c\u800co\u952e\u5219\u662f\u5728\u5149\u6807\u7684\u4e0b\u9762\u518d\u521b\u5efa\u4e00\u4e2a\u7a7a\u884c\uff0c\u6b64\u65f6\u53ef\u6572\u51fba\u952e\u8fdb\u5165\u5230\u7f16\u8f91\u5668\u7684\u8f93\u5165\u6a21\u5f0f\uff0c\u5982\u56fe4-3\u6240\u793a\u3002<\/p>\n

\"\u7b2c2\u6b65\uff1a\u6572\u51fb\u5b57\u6bcd\u201ca\u201d\uff0c\u8fdb\u5165\u8f93\u5165\u6a21\u5f0f\u3002\"<\/p>\n

\u56fe4-3\u00a0 \u5207\u6362\u81f3\u7f16\u8f91\u5668\u7684\u8f93\u5165\u6a21\u5f0f<\/p>\n

\u8fdb\u5165\u8f93\u5165\u6a21\u5f0f\u540e\uff0c\u53ef\u4ee5\u968f\u610f\u8f93\u5165\u6587\u672c\u5185\u5bb9\uff0cVim\u7f16\u8f91\u5668\u4e0d\u4f1a\u628a\u60a8\u8f93\u5165\u7684\u6587\u672c\u5185\u5bb9\u5f53\u4f5c\u547d\u4ee4\u800c\u6267\u884c\uff0c\u5982\u56fe4-4\u6240\u793a\u3002<\/p>\n

\"\u7b2c3\u6b65\uff1a\u8f93\u5165\u4e00\u884c\u5b57\u7b26\u3002\"<\/p>\n

\u56fe4-4\u00a0 \u5728\u7f16\u8f91\u5668\u4e2d\u8f93\u5165\u6587\u672c\u5185\u5bb9<\/p>\n

\u5728\u7f16\u5199\u5b8c\u4e4b\u540e\uff0c\u60f3\u8981\u4fdd\u5b58\u5e76\u9000\u51fa\uff0c\u5fc5\u987b\u5148\u6572\u51fb\u952e\u76d8Esc\u952e\u4ece\u8f93\u5165\u6a21\u5f0f\u8fd4\u56de\u547d\u4ee4\u6a21\u5f0f\uff0c\u5982\u56fe4-5\u6240\u793a\u3002\u7136\u540e\u518d\u8f93\u5165:wq!\u5207\u6362\u5230\u672b\u884c\u6a21\u5f0f\u624d\u80fd\u5b8c\u6210\u4fdd\u5b58\u9000\u51fa\u64cd\u4f5c\uff0c\u5982\u56fe4-6\u6240\u793a\u3002<\/p>\n

\"\u7b2c4\u6b65\uff1a\u6572\u51fb[ESC]\u8fd4\u56de\u5230\u547d\u4ee4\u6a21\u5f0f\u3002\"<\/p>\n

\u56fe4-5\u00a0 Vim\u7f16\u8f91\u5668\u7684\u547d\u4ee4\u6a21\u5f0f<\/p>\n

\"\u7b2c5\u6b65\uff1a\u6572\u51fb\u201c\uff1awq\u201d\uff0c\u4fdd\u5b58\u5e76\u9000\u51fa\u3002\"<\/p>\n

\u56fe4-6\u00a0 Vim\u7f16\u8f91\u5668\u7684\u672b\u884c\u6a21\u5f0f<\/p>\n

\u5f53\u5728\u672b\u884c\u6a21\u5f0f\u4e2d\u8f93\u5165:wq!\u547d\u4ee4\u65f6\uff0c\u5c31\u610f\u5473\u7740\u5f3a\u5236\u4fdd\u5b58\u5e76\u9000\u51fa\u6587\u6863\u3002\u7136\u540e\u4fbf\u53ef\u4ee5\u7528cat\u547d\u4ee4\u67e5\u770b\u4fdd\u5b58\u540e\u7684\u6587\u6863\u5185\u5bb9\u4e86\uff0c\u5982\u56fe4-7\u6240\u793a\u3002<\/p>\n

\"\u7b2c6\u6b65\uff1a\u67e5\u770b\u6587\u6863\u7684\u5185\u5bb9\u3002\"<\/p>\n

\u56fe4-7 \u67e5\u770b\u6587\u6863\u7684\u5185\u5bb9<\/p>\n

\u662f\u4e0d\u662f\u5f88\u7b80\u5355\uff1f\uff01\u7ee7\u7eed\u7f16\u8f91\u8fd9\u4e2a\u6587\u6863\u3002\u56e0\u4e3a\u8981\u5728\u539f\u6709\u6587\u672c\u5185\u5bb9\u7684\u4e0b\u9762\u8ffd\u52a0\u5185\u5bb9\uff0c\u6240\u4ee5\u5728\u547d\u4ee4\u6a21\u5f0f\u4e2d\u6572\u51fbo\u952e\u8fdb\u5165\u8f93\u5165\u6a21\u5f0f\u66f4\u4f1a\u9ad8\u6548\uff0c\u64cd\u4f5c\u5982\u56fe4-8\u3001\u56fe4-9\u4e0e\u56fe4-10\u6240\u793a\u3002<\/p>\n

\"\u7b2c7\u6b65\uff1a\u7f16\u8f91\u6587\u4ef6\u3002\"<\/p>\n

\u56fe4-8\u00a0 \u518d\u6b21\u901a\u8fc7Vim\u7f16\u8f91\u5668\u7f16\u5199\u6587\u6863<\/p>\n

\"\u7b2c8\u6b65\uff1a\u6572\u51fb\u5b57\u6bcd\u201co\u201d\uff0c\u8fdb\u5165\u5230\u8f93\u5165\u6a21\u5f0f\u3002\"<\/p>\n

\u56fe4-9\u00a0 \u8fdb\u5165Vim\u7f16\u8f91\u5668\u7684\u8f93\u5165\u6a21\u5f0f<\/p>\n

\"\u7b2c9\u6b65\uff1a\u8f93\u5165\u4e00\u884c\u5b57\u7b26\u3002\"<\/p>\n

\u56fe4-10\u00a0 \u8ffd\u52a0\u5199\u5165\u4e00\u884c\u6587\u672c\u5185\u5bb9<\/p>\n

\u56e0\u4e3a\u6b64\u65f6\u5df2\u7ecf\u4fee\u6539\u4e86\u6587\u672c\u5185\u5bb9\uff0c\u6240\u4ee5Vim\u7f16\u8f91\u5668\u5728\u6211\u4eec\u5c1d\u8bd5\u76f4\u63a5\u9000\u51fa\u6587\u6863\u800c\u4e0d\u4fdd\u5b58\u7684\u65f6\u5019\u5c31\u4f1a\u62d2\u7edd\u6211\u4eec\u7684\u64cd\u4f5c\u4e86\u3002\u6b64\u65f6\u53ea\u80fd\u5f3a\u5236\u9000\u51fa\u624d\u53ef\u4ee5\u7ed3\u675f\u672c\u6b21\u8f93\u5165\u64cd\u4f5c\uff0c\u5982\u56fe4-11\u3001\u56fe4-12\u548c\u56fe4-13\u6240\u793a\u3002<\/p>\n

\"\u7b2c10\u6b65\uff1a\u8fd4\u56de\u547d\u4ee4\u6a21\u5f0f\u540e\u5c1d\u8bd5\u201c\uff1aq\u201d\u9000\u51fa\u4e0d\u4fdd\u5b58\u3002\"<\/p>\n

\u56fe4-11\u00a0 \u5c1d\u8bd5\u9000\u51fa\u6587\u672c\u7f16\u8f91\u5668<\/p>\n

\"\u7b2c11\u6b65\uff1a\u63d0\u793a\u5185\u5bb9\u5df2\u88ab\u4fee\u6539\uff0c\u4e0d\u80fd\u9000\u51fa\u3002\"<\/p>\n

\u56fe4-12\u00a0 \u56e0\u6587\u4ef6\u5df2\u88ab\u4fee\u6539\u800c\u62d2\u7edd\u9000\u51fa\u64cd\u4f5c<\/p>\n

\u73b0\u5728\u5927\u5bb6\u4e5f\u7b97\u662f\u5177\u6709\u4e86\u4e00\u4e9bVim\u7f16\u8f91\u5668\u7684\u5b9e\u6218\u7ecf\u9a8c\u4e86\uff0c\u5e94\u8be5\u4e5f\u611f\u89c9\u6ca1\u6709\u60f3\u8c61\u4e2d\u90a3\u4e48\u96be\u5427\u3002\u73b0\u5728\u67e5\u770b\u6587\u672c\u7684\u5185\u5bb9\uff0c\u679c\u7136\u53d1\u73b0\u8ffd\u52a0\u8f93\u5165\u7684\u5185\u5bb9\u5e76\u6ca1\u6709\u88ab\u4fdd\u5b58\u4e0b\u6765\uff0c\u5982\u56fe4-14\u6240\u793a\u3002<\/p>\n

\u5927\u5bb6\u5728\u5b66\u5b8c\u4e86\u7406\u8bba\u77e5\u8bc6\u4e4b\u540e\u53c8\u81ea\u5df1\u52a8\u624b\u7f16\u5199\u4e86\u4e00\u4e2a\u6587\u672c\uff0c\u73b0\u5728\u662f\u5426\u611f\u89c9\u6210\u5c31\u6ee1\u6ee1\u5462\uff1f\u63a5\u4e0b\u6765\u5c06\u4f1a\u7531\u6d45\u5165\u6df1\u4e3a\u8bfb\u8005\u5b89\u6392\u4e09\u4e2a\u5c0f\u4efb\u52a1\u3002\u4e3a\u4e86\u5f7b\u5e95\u638c\u63e1Vim\u7f16\u8f91\u5668\u7684\u4f7f\u7528\uff0c\u5927\u5bb6\u4e00\u5b9a\u8981\u9010\u4e2a\u5b8c\u6210\u4e0d\u8bb8\u5077\u61d2\uff0c\u5982\u679c\u5728\u5b8c\u6210\u8fd9\u4e09\u4e2a\u4efb\u52a1\u671f\u95f4\u5fd8\u8bb0\u4e86\u76f8\u5173\u547d\u4ee4\uff0c\u53ef\u8fd4\u56de\u524d\u6587\u8fdb\u4e00\u6b65\u590d\u4e60\u638c\u63e1\u3002<\/p>\n

\"\u7b2c12\u6b65\uff1a\u6572\u51fb\u201c\uff1aq!\u201d\u540e\u5f3a\u5236\u9000\u51fa\u4e0d\u4fdd\u5b58\u3002\"<\/p>\n

\u56fe4-13 \u00a0\u5f3a\u5236\u9000\u51fa\u6587\u672c\u7f16\u8f91\u5668<\/p>\n

\"\u7b2c13\u6b65\uff1a\u67e5\u770b\u6587\u6863\uff0c\u53d1\u73b0\u7b2c\u4e8c\u53e5\u786e\u5b9e\u6ca1\u4fdd\u5b58\u3002\"<\/p>\n

\u56fe4-14 \u00a0\u67e5\u770b\u6700\u7ec8\u7f16\u5199\u6210\u7684\u6587\u672c\u5185\u5bb9<\/p>\n

4.1.2 \u914d\u7f6e\u4e3b\u673a\u540d\u79f0<\/span><\/strong><\/h6>\n

\u4e3a\u4e86\u4fbf\u4e8e\u5728\u5c40\u57df\u7f51\u4e2d\u67e5\u627e\u67d0\u53f0\u7279\u5b9a\u7684\u4e3b\u673a\uff0c\u6216\u8005\u5bf9\u4e3b\u673a\u8fdb\u884c\u533a\u5206\uff0c\u9664\u4e86\u8981\u6709IP\u5730\u5740\u5916\uff0c\u8fd8\u8981\u4e3a\u4e3b\u673a\u914d\u7f6e\u4e00\u4e2a\u4e3b\u673a\u540d\uff0c\u4e3b\u673a\u4e4b\u95f4\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2a\u7c7b\u4f3c\u4e8e\u57df\u540d\u7684\u540d\u79f0\u6765\u76f8\u4e92\u8bbf\u95ee\u3002\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u4e3b\u673a\u540d\u5927\u591a\u4fdd\u5b58\u5728\/etc\/hostname\u6587\u4ef6\u4e2d\uff0c\u63a5\u4e0b\u6765\u5c06\/etc\/hostname\u6587\u4ef6\u7684\u5185\u5bb9\u4fee\u6539\u4e3a\u201clrxjmw.cn\u201d\uff0c\u6b65\u9aa4\u5982\u4e0b\u3002<\/p>\n

\u7b2c1\u6b65<\/strong>\uff1a\u4f7f\u7528Vim\u7f16\u8f91\u5668\u4fee\u6539\u201c\/etc\/hostname\u201d\u4e3b\u673a\u540d\u79f0\u6587\u4ef6\u3002<\/p>\n

\u7b2c2\u6b65<\/strong>\uff1a\u628a\u539f\u59cb\u4e3b\u673a\u540d\u79f0\u5220\u9664\u540e\u8ffd\u52a0\u201clrxjmw.cn\u201d\u3002\u6ce8\u610f\uff0c\u4f7f\u7528Vim\u7f16\u8f91\u5668\u4fee\u6539\u4e3b\u673a\u540d\u79f0\u6587\u4ef6\u540e\uff0c\u8981\u5728\u672b\u884c\u6a21\u5f0f\u4e0b\u6267\u884c:wq!\u547d\u4ee4\u624d\u80fd\u4fdd\u5b58\u5e76\u9000\u51fa\u6587\u6863\u3002<\/p>\n

\u7b2c3\u6b65<\/strong>\uff1a\u4fdd\u5b58\u5e76\u9000\u51fa\u6587\u6863\uff0c\u7136\u540e\u4f7f\u7528hostname\u547d\u4ee4\u68c0\u67e5\u662f\u5426\u4fee\u6539\u6210\u529f\u3002<\/p><\/blockquote>\n

[root@linuxprobe ~]# vim \/etc\/hostname\r\nlrxjmw.cn\r\n<\/pre>\n

hostname\u547d\u4ee4\u7528\u4e8e\u67e5\u770b\u5f53\u524d\u7684\u4e3b\u673a\u540d\u79f0\uff0c\u4f46\u6709\u65f6\u4e3b\u673a\u540d\u79f0\u7684\u6539\u53d8\u4e0d\u4f1a\u7acb\u5373\u540c\u6b65\u5230\u7cfb\u7edf\u4e2d\uff0c\u6240\u4ee5\u5982\u679c\u53d1\u73b0\u4fee\u6539\u5b8c\u6210\u540e\u8fd8\u663e\u793a\u539f\u6765\u7684\u4e3b\u673a\u540d\u79f0\uff0c\u53ef\u91cd\u542f\u865a\u62df\u673a\u540e\u518d\u884c\u67e5\u770b\uff1a<\/p>\n

[root@linuxprobe ~]# hostname\r\nlrxjmw.cn\r\n<\/pre>\n
4.1.3 \u914d\u7f6e\u7f51\u5361\u4fe1\u606f<\/strong><\/span><\/h6>\n

\u7f51\u5361IP\u5730\u5740\u914d\u7f6e\u7684\u662f\u5426\u6b63\u786e\u662f\u4e24\u53f0\u670d\u52a1\u5668\u662f\u5426\u53ef\u4ee5\u76f8\u4e92\u901a\u4fe1\u7684\u524d\u63d0\u3002\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u4e00\u5207\u90fd\u662f\u6587\u4ef6\uff0c\u56e0\u6b64\u914d\u7f6e\u7f51\u7edc\u670d\u52a1\u7684\u5de5\u4f5c\u5176\u5b9e\u5c31\u662f\u5728\u7f16\u8f91\u7f51\u5361\u914d\u7f6e\u6587\u4ef6\uff0c\u56e0\u6b64\u8fd9\u4e2a\u5c0f\u4efb\u52a1\u4e0d\u4ec5\u53ef\u4ee5\u5e2e\u52a9\u60a8\u7ec3\u4e60\u4f7f\u7528Vim\u7f16\u8f91\u5668\uff0c\u800c\u4e14\u4e5f\u4e3a\u60a8\u540e\u9762\u5b66\u4e60Linux\u4e2d\u7684\u5404\u79cd\u670d\u52a1\u914d\u7f6e\u6253\u4e0b\u4e86\u575a\u5b9e\u7684\u57fa\u7840\u3002\u5f53\u60a8\u8ba4\u771f\u5b66\u4e60\u5b8c\u672c\u4e66\u540e\uff0c\u4e00\u5b9a\u4f1a\u7279\u522b\u6709\u6210\u5c31\u611f\uff0c\u56e0\u4e3a\u672c\u4e66\u524d\u9762\u7684\u57fa\u7840\u90e8\u5206\u975e\u5e38\u624e\u5b9e\uff0c\u800c\u540e\u9762\u5185\u5bb9\u5219\u5177\u6709\u51e0\u4e4e\u4e00\u81f4\u7684\u7f51\u5361IP\u5730\u5740\u548c\u8fd0\u884c\u73af\u5883\uff0c\u4ece\u800c\u786e\u4fdd\u60a8\u5168\u8eab\u5fc3\u5730\u6295\u5165\u5230\u5404\u7c7b\u670d\u52a1\u7a0b\u5e8f\u7684\u5b66\u4e60\u4e0a\uff0c\u800c\u4e0d\u7528\u64cd\u5fc3\u7cfb\u7edf\u73af\u5883\u7684\u95ee\u9898\u3002<\/p>\n

\u5982\u679c\u60a8\u5177\u5907\u4e00\u5b9a\u7684\u8fd0\u7ef4\u7ecf\u9a8c\u6216\u8005\u719f\u6089\u65e9\u671f\u7684Linux\u7cfb\u7edf\uff0c\u5219\u5728\u5b66\u4e60\u672c\u4e66\u65f6\u4f1a\u9047\u5230\u4e00\u4e9b\u4e0d\u5bb9\u6613\u63a5\u53d7\u7684\u5dee\u5f02\u53d8\u5316\u3002\u5728RHEL 5\u3001RHEL 6\u4e2d\uff0c\u7f51\u5361\u914d\u7f6e\u6587\u4ef6\u7684\u524d\u7f00\u4e3aeth\uff0c\u7b2c1\u5757\u7f51\u5361\u4e3aeth0\uff0c\u7b2c2\u5757\u7f51\u5361\u4e3aeth1\uff1b\u4ee5\u6b64\u7c7b\u63a8\u3002\u800c\u5728RHEL 7\u4e2d\uff0c\u7f51\u5361\u914d\u7f6e\u6587\u4ef6\u7684\u524d\u7f00\u5219\u4ee5ifcfg\u5f00\u59cb\uff0c\u52a0\u4e0a\u7f51\u5361\u540d\u79f0\u5171\u540c\u7ec4\u6210\u4e86\u7f51\u5361\u914d\u7f6e\u6587\u4ef6\u7684\u540d\u5b57\uff0c\u4f8b\u5982ifcfg-eno16777736\uff1b\u597d\u5728\u9664\u4e86\u6587\u4ef6\u540d\u53d8\u5316\u5916\u4e5f\u6ca1\u6709\u5176\u4ed6\u5927\u7684\u533a\u522b\u3002<\/p>\n

\u73b0\u5728\u6709\u4e00\u4e2a\u540d\u79f0\u4e3aifcfg-eno16777736\u7684\u7f51\u5361\u8bbe\u5907\uff0c\u6211\u4eec\u5c06\u5176\u914d\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u52a8\uff0c\u5e76\u4e14IP\u5730\u5740\u3001\u5b50\u7f51\u3001\u7f51\u5173\u7b49\u4fe1\u606f\u7531\u4eba\u5de5\u6307\u5b9a\uff0c\u5176\u6b65\u9aa4\u5e94\u8be5\u5982\u4e0b\u6240\u793a\u3002<\/p>\n

\u7b2c1\u6b65<\/strong>\uff1a\u9996\u5148\u5207\u6362\u5230\/etc\/sysconfig\/network-scripts\u76ee\u5f55\u4e2d\uff08\u5b58\u653e\u7740\u7f51\u5361\u7684\u914d\u7f6e\u6587\u4ef6\uff09\u3002<\/p>\n

\u7b2c2\u6b65<\/strong>\uff1a\u4f7f\u7528Vim\u7f16\u8f91\u5668\u4fee\u6539\u7f51\u5361\u6587\u4ef6ifcfg-eno16777736\uff0c\u9010\u9879\u5199\u5165\u4e0b\u9762\u7684\u914d\u7f6e\u53c2\u6570\u5e76\u4fdd\u5b58\u9000\u51fa\u3002\u7531\u4e8e\u6bcf\u53f0\u8bbe\u5907\u7684\u786c\u4ef6\u53ca\u67b6\u6784\u662f\u4e0d\u4e00\u6837\u7684\uff0c\u56e0\u6b64\u8bf7\u8bfb\u8005\u4f7f\u7528ifconfig\u547d\u4ee4\u81ea\u884c\u786e\u8ba4\u5404\u81ea\u7f51\u5361\u7684\u9ed8\u8ba4\u540d\u79f0\u3002<\/p>\n

\u8bbe\u5907\u7c7b\u578b\uff1aTYPE=Ethernet<\/p>\n

\u5730\u5740\u5206\u914d\u6a21\u5f0f\uff1aBOOTPROTO=static<\/p>\n

\u7f51\u5361\u540d\u79f0\uff1aNAME=eno16777736<\/p>\n

\u662f\u5426\u542f\u52a8\uff1aONBOOT=yes<\/p>\n

IP\u5730\u5740\uff1aIPADDR=192.168.10.10<\/p>\n

\u5b50\u7f51\u63a9\u7801\uff1aNETMASK=255.255.255.0<\/p>\n

\u7f51\u5173\u5730\u5740\uff1aGATEWAY=192.168.10.1<\/p>\n

DNS\u5730\u5740\uff1aDNS1=192.168.10.1<\/p><\/blockquote>\n

\u7b2c3\u6b65<\/strong>\uff1a\u91cd\u542f\u7f51\u7edc\u670d\u52a1\u5e76\u6d4b\u8bd5\u7f51\u7edc\u662f\u5426\u8054\u901a\u3002<\/p>\n

\u8fdb\u5165\u5230\u7f51\u5361\u914d\u7f6e\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u7f16\u8f91\u7f51\u5361\u914d\u7f6e\u6587\u4ef6\uff0c\u5728\u5176\u4e2d\u586b\u5165\u4e0b\u9762\u7684\u4fe1\u606f\uff1a<\/p>\n

[root@linuxprobe ~]# cd \/etc\/sysconfig\/network-scripts\/\r\n[root@linuxprobe network-scripts]# vim ifcfg-eno16777736\r\nTYPE=Ethernet\r\nBOOTPROTO=static\r\nNAME=eno16777736\r\nONBOOT=yes\r\nIPADDR=192.168.10.10\r\nNETMASK=255.255.255.0\r\nGATEWAY=192.168.10.1\r\nDNS1=192.168.10.1<\/pre>\n

\u6267\u884c\u91cd\u542f\u7f51\u5361\u8bbe\u5907\u7684\u547d\u4ee4\uff08\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\u4e0d\u4f1a\u6709\u63d0\u793a\u4fe1\u606f\uff09\uff0c\u7136\u540e\u901a\u8fc7ping\u547d\u4ee4\u6d4b\u8bd5\u7f51\u7edc\u80fd\u5426\u8054\u901a\u3002\u7531\u4e8e\u5728Linux\u7cfb\u7edf\u4e2dping\u547d\u4ee4\u4e0d\u4f1a\u81ea\u52a8\u7ec8\u6b62\uff0c\u56e0\u6b64\u9700\u8981\u624b\u52a8\u6309\u4e0bCtrl-c\u952e\u6765\u5f3a\u884c\u7ed3\u675f\u8fdb\u7a0b\u3002<\/p>\n

[root@linuxprobe network-scripts]# systemctl restart network\r\n[root@linuxprobe network-scripts]# ping 192.168.10.10\r\nPING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.\r\n64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.081 ms\r\n64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.083 ms\r\n64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.059 ms\r\n64 bytes from 192.168.10.10: icmp_seq=4 ttl=64 time=0.097 ms\r\n^C\r\n--- 192.168.10.10 ping statistics ---\r\n4 packets transmitted, 4 received, 0% packet loss, time 2999ms\r\nrtt min\/avg\/max\/mdev = 0.059\/0.080\/0.097\/0.013 ms\r\n<\/pre>\n
4.1.4 \u914d\u7f6eYum\u4ed3\u5e93<\/strong><\/span><\/h6>\n

\u672c\u4e66\u524d\u9762\u8bb2\u5230\uff0cYum\u8f6f\u4ef6\u4ed3\u5e93\u7684\u4f5c\u7528\u662f\u4e3a\u4e86\u8fdb\u4e00\u6b65\u7b80\u5316RPM\u7ba1\u7406\u8f6f\u4ef6\u7684\u96be\u5ea6\u4ee5\u53ca\u81ea\u52a8\u5206\u6790\u6240\u9700\u8f6f\u4ef6\u5305\u53ca\u5176\u4f9d\u8d56\u5173\u7cfb\u7684\u6280\u672f\u3002\u53ef\u4ee5\u628aYum\u60f3\u8c61\u6210\u662f\u4e00\u4e2a\u7855\u5927\u7684\u8f6f\u4ef6\u4ed3\u5e93\uff0c\u91cc\u9762\u4fdd\u5b58\u6709\u51e0\u4e4e\u6240\u6709\u5e38\u7528\u7684\u5de5\u5177\uff0c\u800c\u4e14\u53ea\u9700\u8981\u8bf4\u51fa\u6240\u9700\u7684\u8f6f\u4ef6\u5305\u540d\u79f0\uff0c\u7cfb\u7edf\u5c31\u4f1a\u81ea\u52a8\u4e3a\u60a8\u641e\u5b9a\u4e00\u5207\u3002<\/p>\n

\u65e2\u7136\u8981\u4f7f\u7528Yum\u8f6f\u4ef6\u4ed3\u5e93\uff0c\u5c31\u8981\u5148\u628a\u5b83\u642d\u5efa\u8d77\u6765\uff0c\u7136\u540e\u5c06\u5176\u914d\u7f6e\u89c4\u5219\u786e\u5b9a\u597d\u624d\u884c\u3002\u9274\u4e8e\u7b2c6\u7ae0\u624d\u4f1a\u8bb2\u89e3Linux\u7684\u5b58\u50a8\u7ed3\u6784\u548c\u8bbe\u5907\u6302\u8f7d\u64cd\u4f5c\uff0c\u6240\u4ee5\u6211\u4eec\u5f53\u524d\u8fd8\u662f\u5c06\u91cd\u5fc3\u653e\u5230Vim\u7f16\u8f91\u5668\u7684\u5b66\u4e60\u4e0a\u3002\u5982\u679c\u9047\u5230\u770b\u4e0d\u61c2\u7684\u53c2\u6570\u4e5f\u4e0d\u8981\u7d27\uff0c\u540e\u9762\u7ae0\u8282\u4f1a\u5355\u72ec\u8bb2\u89e3\u3002\u642d\u5efa\u5e76\u914d\u7f6eYum\u8f6f\u4ef6\u4ed3\u5e93\u7684\u5927\u81f4\u6b65\u9aa4\u5982\u4e0b\u6240\u793a\u3002<\/p>\n

\u7b2c1\u6b65<\/strong>\uff1a\u8fdb\u5165\u5230\/etc\/yum.repos.d\/\u76ee\u5f55\u4e2d\uff08\u56e0\u4e3a\u8be5\u76ee\u5f55\u5b58\u653e\u7740Yum\u8f6f\u4ef6\u4ed3\u5e93\u7684\u914d\u7f6e\u6587\u4ef6\uff09\u3002<\/p>\n

\u7b2c2\u6b65<\/strong>\uff1a\u4f7f\u7528Vim\u7f16\u8f91\u5668\u521b\u5efa\u4e00\u4e2a\u540d\u4e3arhel7.repo\u7684\u65b0\u914d\u7f6e\u6587\u4ef6\uff08\u6587\u4ef6\u540d\u79f0\u53ef\u968f\u610f\uff0c\u4f46\u540e\u7f00\u5fc5\u987b\u4e3a.repo\uff09\uff0c\u9010\u9879\u5199\u5165\u4e0b\u9762\u52a0\u7c97\u7684\u914d\u7f6e\u53c2\u6570\u5e76\u4fdd\u5b58\u9000\u51fa\uff08\u4e0d\u8981\u5199\u540e\u9762\u7684\u4e2d\u6587\u6ce8\u91ca\uff09\u3002<\/p>\n

[rhel-media] <\/strong>\uff1aYum\u8f6f\u4ef6\u4ed3\u5e93\u552f\u4e00\u6807\u8bc6\u7b26\uff0c\u907f\u514d\u4e0e\u5176\u4ed6\u4ed3\u5e93\u51b2\u7a81\u3002<\/p>\n

name=linuxprobe<\/strong>\uff1aYum\u8f6f\u4ef6\u4ed3\u5e93\u7684\u540d\u79f0\u63cf\u8ff0\uff0c\u6613\u4e8e\u8bc6\u522b\u4ed3\u5e93\u7528\u5904\u3002<\/p>\n

baseurl=file:\/\/\/media\/cdrom<\/strong>\uff1a\u63d0\u4f9b\u7684\u65b9\u5f0f\u5305\u62ecFTP\uff08ftp:\/\/..\uff09\u3001HTTP\uff08http:\/\/..\uff09\u3001\u672c\u5730\uff08file:\/\/\/..\uff09\u3002<\/p>\n

enabled=1<\/strong>\uff1a\u8bbe\u7f6e\u6b64\u6e90\u662f\u5426\u53ef\u7528\uff1b1\u4e3a\u53ef\u7528\uff0c0\u4e3a\u7981\u7528\u3002<\/p>\n

gpgcheck=1<\/strong>\uff1a\u8bbe\u7f6e\u6b64\u6e90\u662f\u5426\u6821\u9a8c\u6587\u4ef6\uff1b1\u4e3a\u6821\u9a8c\uff0c0\u4e3a\u4e0d\u6821\u9a8c\u3002<\/p>\n

gpgkey=file:\/\/\/media\/cdrom\/RPM-GPG-KEY-redhat-release<\/strong>\uff1a\u82e5\u4e0a\u9762\u53c2\u6570\u5f00\u542f\u6821\u9a8c\uff0c\u90a3\u4e48\u8bf7\u6307\u5b9a\u516c\u94a5\u6587\u4ef6\u5730\u5740\u3002<\/p><\/blockquote>\n

\u7b2c3\u6b65<\/strong>\uff1a\u6309\u914d\u7f6e\u53c2\u6570\u7684\u8def\u5f84\u6302\u8f7d\u5149\u76d8\uff0c\u5e76\u628a\u5149\u76d8\u6302\u8f7d\u4fe1\u606f\u5199\u5165\u5230\/etc\/fstab\u6587\u4ef6\u4e2d\u3002<\/p>\n

\u7b2c4\u6b65<\/strong>\uff1a\u4f7f\u7528\u201cyum install httpd -y\u201d\u547d\u4ee4\u68c0\u67e5Yum\u8f6f\u4ef6\u4ed3\u5e93\u662f\u5426\u5df2\u7ecf\u53ef\u7528\u3002<\/p>\n

\u8fdb\u5165\/etc\/yum.repos.d\u76ee\u5f55\u4e2d\u540e\u521b\u5efaYum\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n

[root@linuxprobe ~]# cd \/etc\/yum.repos.d\/\r\n[root@linuxprobe yum.repos.d]# vim rhel7.repo\r\n[rhel7]\r\nname=rhel7\r\nbaseurl=file:\/\/\/media\/cdrom\r\nenabled=1\r\ngpgcheck=0\r\n<\/pre>\n

\u521b\u5efa\u6302\u8f7d\u70b9\u540e\u8fdb\u884c\u6302\u8f7d\u64cd\u4f5c\uff0c\u5e76\u8bbe\u7f6e\u6210\u5f00\u673a\u81ea\u52a8\u6302\u8f7d\uff08\u8be6\u89c1\u7b2c6\u7ae0\uff09\u3002\u5c1d\u8bd5\u4f7f\u7528Yum\u8f6f\u4ef6\u4ed3\u5e93\u6765\u5b89\u88c5Web\u670d\u52a1\uff0c\u51fa\u73b0Complete<\/strong>\uff01\u5219\u4ee3\u8868\u914d\u7f6e\u6b63\u786e\uff1a<\/p>\n

[root@linuxprobe\u00a0yum.repos.d]#\u00a0mkdir\u00a0-p\u00a0\/media\/cdrom\r\n[root@linuxprobe\u00a0yum.repos.d]#\u00a0mount\u00a0\/dev\/cdrom\u00a0\/media\/cdrom\r\nmount:\u00a0\/dev\/sr0\u00a0is\u00a0write-protected,\u00a0mounting\u00a0read-only\r\n[root@linuxprobe\u00a0yum.repos.d]#\u00a0vim\u00a0\/etc\/fstab\r\n\/dev\/cdrom\u00a0\/media\/cdrom\u00a0iso9660\u00a0defaults\u00a00\u00a00\r\n[root@linuxprobe ~]# yum install httpd\r\nLoaded plugins: langpacks, product-id, subscription-manager\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\nDependencies Resolved\r\n================================================================================\r\n Package Arch Version Repository Size\r\n================================================================================\r\nInstalling:\r\n httpd x86_64 2.4.6-17.el7 rhel 1.2 M\r\nInstalling for dependencies:\r\n apr x86_64 1.4.8-3.el7 rhel 103 k\r\n apr-util x86_64 1.5.2-6.el7 rhel 92 k\r\n httpd-tools x86_64 2.4.6-17.el7 rhel 77 k\r\n mailcap noarch 2.1.41-2.el7 rhel 31 k\r\nTransaction Summary\r\n================================================================================\r\nInstall 1 Package (+4 Dependent packages)\r\nTotal download size: 1.5 M\r\nInstalled size: 4.3 M\r\nIs this ok [y\/d\/N]: y<\/strong>\r\nDownloading packages:\r\n--------------------------------------------------------------------------------\r\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026\r\nComplete!<\/strong><\/pre>\n

\u51fa\u73b0\u95ee\u9898?\u5927\u80c6\u63d0\u95ee!<\/strong><\/span><\/p>\n

\u56e0\u8bfb\u8005\u4eec\u786c\u4ef6\u4e0d\u540c\u6216\u64cd\u4f5c\u9519\u8bef\u90fd\u53ef\u80fd\u5bfc\u81f4\u5b9e\u9a8c\u914d\u7f6e\u51fa\u9519\uff0c\u8bf7\u8010\u5fc3\u518d\u4ed4\u7ec6\u770b\u770b\u64cd\u4f5c\u6b65\u9aa4\u5427\uff0c\u4e0d\u8981\u6c14\u9981~<\/p>\n

Linux\u6280\u672f\u4ea4\u6d41\u8bf7\u52a0A\u7fa4\uff1a560843(\u6ee1<\/span><\/strong>)\uff0cB\u7fa4\uff1a340829(\u63a8\u8350<\/span><\/strong>)\uff0cC\u7fa4\uff1a463590\uff08\u63a8\u8350<\/span><\/strong>\uff09\uff0c\u70b9\u6b64\u67e5\u770b\u5168\u56fd\u7fa4<\/a>\u3002<\/p>\n

*\u672c\u7fa4\u7279\u8272\uff1a\u901a\u8fc7\u53e3\u4ee4\u9a8c\u8bc1\u786e\u4fdd\u6bcf\u4e00\u4e2a\u7fa4\u5458\u90fd\u662f\u300aLinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b\u7684\u8bfb\u8005\uff0c\u7b54\u7591\u66f4\u6709\u9488\u5bf9\u6027\uff0c\u4e0d\u5b9a\u671f\u514d\u8d39\u9886\u53d6\u5b9a\u5236\u793c\u54c1\u3002<\/p><\/blockquote>\n

4.2 \u7f16\u5199Shell\u811a\u672c<\/strong><\/span><\/h5>\n

\u53ef\u4ee5\u5c06Shell\u7ec8\u7aef\u89e3\u91ca\u5668\u5f53\u4f5c\u4eba\u4e0e\u8ba1\u7b97\u673a\u786c\u4ef6\u4e4b\u95f4\u7684\u201c\u7ffb\u8bd1\u5b98\u201d\uff0c\u5b83\u4f5c\u4e3a\u7528\u6237\u4e0eLinux\u7cfb\u7edf\u5185\u90e8\u7684\u901a\u4fe1\u5a92\u4ecb\uff0c\u9664\u4e86\u80fd\u591f\u652f\u6301\u5404\u79cd\u53d8\u91cf\u4e0e\u53c2\u6570\u5916\uff0c\u8fd8\u63d0\u4f9b\u4e86\u8bf8\u5982\u5faa\u73af\u3001\u5206\u652f\u7b49\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\u624d\u6709\u7684\u63a7\u5236\u7ed3\u6784\u7279\u6027\u3002\u8981\u60f3\u6b63\u786e\u4f7f\u7528Shell\u4e2d\u7684\u8fd9\u4e9b\u529f\u80fd\u7279\u6027\uff0c\u51c6\u786e\u4e0b\u8fbe\u547d\u4ee4\u5c24\u4e3a\u91cd\u8981\u3002Shell\u811a\u672c\u547d\u4ee4\u7684\u5de5\u4f5c\u65b9\u5f0f\u6709\u4e24\u79cd\uff1a\u4ea4\u4e92\u5f0f\u548c\u6279\u5904\u7406\u3002<\/p>\n

\u4ea4\u4e92\u5f0f\uff08Interactive\uff09\uff1a\u7528\u6237\u6bcf\u8f93\u5165\u4e00\u6761\u547d\u4ee4\u5c31\u7acb\u5373\u6267\u884c\u3002<\/p>\n

\u6279\u5904\u7406\uff08Batch\uff09\uff1a\u7531\u7528\u6237\u4e8b\u5148\u7f16\u5199\u597d\u4e00\u4e2a\u5b8c\u6574\u7684Shell\u811a\u672c\uff0cShell\u4f1a\u4e00\u6b21\u6027\u6267\u884c\u811a\u672c\u4e2d\u8bf8\u591a\u7684\u547d\u4ee4\u3002<\/p><\/blockquote>\n

\u5728Shell\u811a\u672c\u4e2d\u4e0d\u4ec5\u4f1a\u7528\u5230\u524d\u9762\u5b66\u4e60\u8fc7\u7684\u5f88\u591aLinux\u547d\u4ee4\u4ee5\u53ca\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u7ba1\u9053\u7b26\u3001\u6570\u636e\u6d41\u91cd\u5b9a\u5411\u7b49\u8bed\u6cd5\u89c4\u5219\uff0c\u8fd8\u9700\u8981\u628a\u5185\u90e8\u529f\u80fd\u6a21\u5757\u5316\u540e\u901a\u8fc7\u903b\u8f91\u8bed\u53e5\u8fdb\u884c\u5904\u7406\uff0c\u6700\u7ec8\u5f62\u6210\u65e5\u5e38\u6240\u89c1\u7684Shell\u811a\u672c\u3002<\/p>\n

\u67e5\u770bSHELL\u53d8\u91cf\u53ef\u4ee5\u53d1\u73b0\u5f53\u524d\u7cfb\u7edf\u5df2\u7ecf\u9ed8\u8ba4\u4f7f\u7528Bash\u4f5c\u4e3a\u547d\u4ee4\u884c\u7ec8\u7aef\u89e3\u91ca\u5668\u4e86\uff1a<\/p>\n

[root@linuxprobe ~]# echo $SHELL\r\n\/bin\/bash<\/pre>\n
4.2.1 \u7f16\u5199\u7b80\u5355\u7684\u811a\u672c<\/strong><\/span><\/h6>\n

\u4f30\u8ba1\u8bfb\u8005\u5728\u770b\u5b8c\u4e0a\u6587\u4e2d\u6709\u5173Shell\u811a\u672c\u7684\u590d\u6742\u63cf\u8ff0\u540e\uff0c\u4f1a\u7d2f\u89c9\u4e0d\u7231\u5427\u3002\u4f46\u662f\uff0c\u4e0a\u6587\u6307\u7684\u662f\u4e00\u4e2a\u9ad8\u7ea7Shell\u811a\u672c\u7684\u7f16\u5199\u539f\u5219\uff0c\u5176\u5b9e\u4f7f\u7528Vim\u7f16\u8f91\u5668\u628aLinux\u547d\u4ee4\u6309\u7167\u987a\u5e8f\u4f9d\u6b21\u5199\u5165\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u8fd9\u5c31\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u811a\u672c\u4e86\u3002<\/p>\n

\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u67e5\u770b\u5f53\u524d\u6240\u5728\u5de5\u4f5c\u8def\u5f84\u5e76\u5217\u51fa\u5f53\u524d\u76ee\u5f55\u4e0b\u6240\u6709\u7684\u6587\u4ef6\u53ca\u5c5e\u6027\u4fe1\u606f\uff0c\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u7684\u811a\u672c\u5e94\u8be5\u7c7b\u4f3c\u4e8e\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n

[root@linuxprobe ~]# vim example.sh\r\n#!\/bin\/bash \r\n#For Example BY lrxjmw.cn \r\npwd \r\nls -al<\/pre>\n

Shell\u811a\u672c\u6587\u4ef6\u7684\u540d\u79f0\u53ef\u4ee5\u4efb\u610f\uff0c\u4f46\u4e3a\u4e86\u907f\u514d\u88ab\u8bef\u4ee5\u4e3a\u662f\u666e\u901a\u6587\u4ef6\uff0c\u5efa\u8bae\u5c06.sh\u540e\u7f00\u52a0\u4e0a\uff0c\u4ee5\u8868\u793a\u662f\u4e00\u4e2a\u811a\u672c\u6587\u4ef6\u3002\u5728\u4e0a\u9762\u7684\u8fd9\u4e2aexample.sh\u811a\u672c\u4e2d\u5b9e\u9645\u4e0a\u51fa\u73b0\u4e86\u4e09\u79cd\u4e0d\u540c\u7684\u5143\u7d20\uff1a\u7b2c\u4e00\u884c\u7684\u811a\u672c\u58f0\u660e\uff08#!\uff09\u7528\u6765\u544a\u8bc9\u7cfb\u7edf\u4f7f\u7528\u54ea\u79cdShell\u89e3\u91ca\u5668\u6765\u6267\u884c\u8be5\u811a\u672c\uff1b\u7b2c\u4e8c\u884c\u7684\u6ce8\u91ca\u4fe1\u606f\uff08#\uff09\u662f\u5bf9\u811a\u672c\u529f\u80fd\u548c\u67d0\u4e9b\u547d\u4ee4\u7684\u4ecb\u7ecd\u4fe1\u606f\uff0c\u4f7f\u5f97\u81ea\u5df1\u6216\u4ed6\u4eba\u5728\u65e5\u540e\u770b\u5230\u8fd9\u4e2a\u811a\u672c\u5185\u5bb9\u65f6\uff0c\u53ef\u4ee5\u5feb\u901f\u77e5\u9053\u8be5\u811a\u672c\u7684\u4f5c\u7528\u6216\u4e00\u4e9b\u8b66\u544a\u4fe1\u606f\uff1b\u7b2c\u4e09\u3001\u56db\u884c\u7684\u53ef\u6267\u884c\u8bed\u53e5\u4e5f\u5c31\u662f\u6211\u4eec\u5e73\u65f6\u6267\u884c\u7684Linux\u547d\u4ee4\u4e86\u3002\u4ec0\u4e48\uff1f\uff01\u4f60\u4eec\u4e0d\u76f8\u4fe1\u8fd9\u4e48\u7b80\u5355\u5c31\u7f16\u5199\u51fa\u6765\u4e86\u4e00\u4e2a\u811a\u672c\u7a0b\u5e8f\uff0c\u90a3\u6211\u4eec\u6765\u6267\u884c\u4e00\u4e0b\u770b\u770b\u7ed3\u679c\uff1a<\/p>\n

[root@linuxprobe ~]# bash example.sh\r\n\/root\/Desktop\r\ntotal 8\r\ndrwxr-xr-x. 2 root root 23 Jul 23 17:31 .\r\ndr-xr-x---. 14 root root 4096 Jul 23 17:31 ..\r\n-rwxr--r--. 1 root root 55 Jul 23 17:31 example.sh<\/pre>\n

\u9664\u4e86\u4e0a\u9762\u7528bash\u89e3\u91ca\u5668\u547d\u4ee4\u76f4\u63a5\u8fd0\u884cShell\u811a\u672c\u6587\u4ef6\u5916\uff0c\u7b2c\u4e8c\u79cd\u8fd0\u884c\u811a\u672c\u7a0b\u5e8f\u7684\u65b9\u6cd5\u662f\u901a\u8fc7\u8f93\u5165\u5b8c\u6574\u8def\u5f84\u7684\u65b9\u5f0f\u6765\u6267\u884c\u3002\u4f46\u9ed8\u8ba4\u4f1a\u56e0\u4e3a\u6743\u9650\u4e0d\u8db3\u800c\u63d0\u793a\u62a5\u9519\u4fe1\u606f\uff0c\u6b64\u65f6\u53ea\u9700\u8981\u4e3a\u811a\u672c\u6587\u4ef6\u589e\u52a0\u6267\u884c\u6743\u9650\u5373\u53ef\uff08\u8be6\u89c1\u7b2c5\u7ae0\uff09\u3002\u521d\u6b21\u5b66\u4e60Linux\u7cfb\u7edf\u7684\u8bfb\u8005\u4e0d\u7528\u5fc3\u6025\uff0c\u7b49\u4e0b\u4e00\u7ae0\u5b66\u5b8c\u7528\u6237\u8eab\u4efd\u548c\u6743\u9650\u540e\u518d\u6765\u505a\u8fd9\u4e2a\u5b9e\u9a8c\u4e5f\u4e0d\u8fdf\uff1a<\/p>\n

[root@linuxprobe ~]# .\/example.sh\r\nbash: .\/Example.sh: Permission denied\r\n[root@linuxprobe ~]# chmod u+x example.sh\r\n[root@linuxprobe ~]# .\/example.sh\r\n\/root\/Desktop\r\ntotal 8\r\ndrwxr-xr-x. 2 root root 23 Jul 23 17:31 .\r\ndr-xr-x---. 14 root root 4096 Jul 23 17:31 ..\r\n-rwxr--r--. 1 root root 55 Jul 23 17:31 example.sh<\/pre>\n
4.2.2 \u63a5\u6536\u7528\u6237\u7684\u53c2\u6570<\/strong><\/span><\/h6>\n

\u4f46\u662f\uff0c\u50cf\u4e0a\u9762\u8fd9\u6837\u7684\u811a\u672c\u7a0b\u5e8f\u53ea\u80fd\u6267\u884c\u4e00\u4e9b\u9884\u5148\u5b9a\u4e49\u597d\u7684\u529f\u80fd\uff0c\u672a\u514d\u592a\u8fc7\u6b7b\u677f\u4e86\u3002\u4e3a\u4e86\u8ba9Shell\u811a\u672c\u7a0b\u5e8f\u66f4\u597d\u5730\u6ee1\u8db3\u7528\u6237\u7684\u4e00\u4e9b\u5b9e\u65f6\u9700\u6c42\uff0c\u4ee5\u4fbf\u7075\u6d3b\u5b8c\u6210\u5de5\u4f5c\uff0c\u5fc5\u987b\u8981\u8ba9\u811a\u672c\u7a0b\u5e8f\u80fd\u591f\u50cf\u4e4b\u524d\u6267\u884c\u547d\u4ee4\u65f6\u90a3\u6837\uff0c\u63a5\u6536\u7528\u6237\u8f93\u5165\u7684\u53c2\u6570\u3002<\/p>\n

\u5176\u5b9e\uff0cLinux\u7cfb\u7edf\u4e2d\u7684Shell\u811a\u672c\u8bed\u8a00\u65e9\u5c31\u8003\u8651\u5230\u4e86\u8fd9\u4e9b\uff0c\u5df2\u7ecf\u5185\u8bbe\u4e86\u7528\u4e8e\u63a5\u6536\u53c2\u6570\u7684\u53d8\u91cf\uff0c\u53d8\u91cf\u4e4b\u95f4\u53ef\u4ee5\u4f7f\u7528\u7a7a\u683c\u95f4\u9694\u3002\u4f8b\u5982$0\u5bf9\u5e94\u7684\u662f\u5f53\u524dShell\u811a\u672c\u7a0b\u5e8f\u7684\u540d\u79f0\uff0c$#\u5bf9\u5e94\u7684\u662f\u603b\u5171\u6709\u51e0\u4e2a\u53c2\u6570\uff0c$*\u5bf9\u5e94\u7684\u662f\u6240\u6709\u4f4d\u7f6e\u7684\u53c2\u6570\u503c\uff0c$?\u5bf9\u5e94\u7684\u662f\u663e\u793a\u4e0a\u4e00\u6b21\u547d\u4ee4\u7684\u6267\u884c\u8fd4\u56de\u503c\uff0c\u800c$1\u3001$2\u3001$3\u2026\u2026\u5219\u5206\u522b\u5bf9\u5e94\u7740\u7b2cN\u4e2a\u4f4d\u7f6e\u7684\u53c2\u6570\u503c\uff0c\u5982\u56fe4-15\u6240\u793a\u3002<\/p>\n

\"\"<\/p>\n

\u56fe4-15\u00a0 Shell\u811a\u672c\u7a0b\u5e8f\u4e2d\u7684\u53c2\u6570\u4f4d\u7f6e\u53d8\u91cf<\/p>\n

\u7406\u8bba\u8fc7\u540e\u6211\u4eec\u6765\u7ec3\u4e60\u4e00\u4e0b\u3002\u5c1d\u8bd5\u7f16\u5199\u4e00\u4e2a\u811a\u672c\u7a0b\u5e8f\u793a\u4f8b\uff0c\u901a\u8fc7\u5f15\u7528\u4e0a\u9762\u7684\u53d8\u91cf\u53c2\u6570\u6765\u770b\u4e0b\u771f\u5b9e\u6548\u679c\uff1a<\/p>\n

[root@linuxprobe ~]# vim example.sh\r\n#!\/bin\/bash\r\necho \"\u5f53\u524d\u811a\u672c\u540d\u79f0\u4e3a$0\"\r\necho \"\u603b\u5171\u6709$#\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u662f$*\u3002\"\r\necho \"\u7b2c1\u4e2a\u53c2\u6570\u4e3a$1\uff0c\u7b2c5\u4e2a\u4e3a$5\u3002\"\r\n[root@linuxprobe ~]# sh example.sh one two three four five six\r\n\u5f53\u524d\u811a\u672c\u540d\u79f0\u4e3aexample.sh\r\n\u603b\u5171\u67096\u4e2a\u53c2\u6570\uff0c\u5206\u522b\u662fone two three four five six\u3002\r\n\u7b2c1\u4e2a\u53c2\u6570\u4e3aone\uff0c\u7b2c5\u4e2a\u4e3afive\u3002\r\n<\/pre>\n
4.2.3 \u5224\u65ad\u7528\u6237\u7684\u53c2\u6570<\/strong><\/span><\/h6>\n

\u5b66\u4e60\u662f\u4e00\u4e2a\u767b\u5802\u5165\u5ba4\u3001\u7531\u6d45\u5165\u6df1\u7684\u8fc7\u7a0b\u3002\u5728\u5b66\u4e60\u5b8cLinux\u547d\u4ee4\u3001\u638c\u63e1Shell\u811a\u672c\u8bed\u6cd5\u53d8\u91cf\u548c\u63a5\u6536\u7528\u6237\u8f93\u5165\u7684\u4fe1\u606f\u4e4b\u540e\uff0c\u5c31\u8981\u8e0f\u4e0a\u65b0\u7684\u9ad8\u5ea6\u2014\u80fd\u591f\u8fdb\u4e00\u6b65\u5904\u7406\u63a5\u6536\u5230\u7684\u7528\u6237\u53c2\u6570\u3002<\/p>\n

\u5728\u672c\u4e66\u524d\u9762\u7ae0\u8282\u4e2d\u8bb2\u5230\uff0c\u7cfb\u7edf\u5728\u6267\u884cmkdir\u547d\u4ee4\u65f6\u4f1a\u5224\u65ad\u7528\u6237\u8f93\u5165\u7684\u4fe1\u606f\uff0c\u5373\u5224\u65ad\u7528\u6237\u6307\u5b9a\u7684\u6587\u4ef6\u5939\u540d\u79f0\u662f\u5426\u5df2\u7ecf\u5b58\u5728\uff0c\u5982\u679c\u5b58\u5728\u5219\u63d0\u793a\u62a5\u9519\uff1b\u53cd\u4e4b\u5219\u81ea\u52a8\u521b\u5efa\u3002Shell\u811a\u672c\u4e2d\u7684\u6761\u4ef6\u6d4b\u8bd5\u8bed\u6cd5\u53ef\u4ee5\u5224\u65ad\u8868\u8fbe\u5f0f\u662f\u5426\u6210\u7acb\uff0c\u82e5\u6761\u4ef6\u6210\u7acb\u5219\u8fd4\u56de\u6570\u5b570\uff0c\u5426\u5219\u4fbf\u8fd4\u56de\u5176\u4ed6\u968f\u673a\u6570\u503c\u3002\u6761\u4ef6\u6d4b\u8bd5\u8bed\u6cd5\u7684\u6267\u884c\u683c\u5f0f\u5982\u56fe4-16\u6240\u793a\u3002\u5207\u8bb0\uff0c\u6761\u4ef6\u8868\u8fbe\u5f0f\u4e24\u8fb9\u5747\u5e94\u6709\u4e00\u4e2a\u7a7a\u683c\u3002<\/p>\n

\"\u6d4b\u8bd5\u8bed\u53e5\u683c\u5f0f\"<\/p>\n

\u56fe4-16\u00a0 \u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u7684\u6267\u884c\u683c\u5f0f<\/p>\n


\n

\u6309\u7167\u6d4b\u8bd5\u5bf9\u8c61\u6765\u5212\u5206\uff0c\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u53ef\u4ee5\u5206\u4e3a4\u79cd\uff1a<\/p>\n

\u6587\u4ef6\u6d4b\u8bd5\u8bed\u53e5\uff1b<\/p>\n

\u903b\u8f91\u6d4b\u8bd5\u8bed\u53e5\uff1b<\/p>\n

\u6574\u6570\u503c\u6bd4\u8f83\u8bed\u53e5\uff1b<\/p>\n

\u5b57\u7b26\u4e32\u6bd4\u8f83\u8bed\u53e5\u3002<\/p><\/blockquote>\n

\u6587\u4ef6\u6d4b\u8bd5\u5373\u4f7f\u7528\u6307\u5b9a\u6761\u4ef6\u6765\u5224\u65ad\u6587\u4ef6\u662f\u5426\u5b58\u5728\u6216\u6743\u9650\u662f\u5426\u6ee1\u8db3\u7b49\u60c5\u51b5\u7684\u8fd0\u7b97\u7b26\uff0c\u5177\u4f53\u7684\u53c2\u6570\u5982\u88684-3\u6240\u793a\u3002<\/p>\n

\u88684-3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u6587\u4ef6\u6d4b\u8bd5\u6240\u7528\u7684\u53c2\u6570<\/p>\n\n\n\n\n\n\n\n\n\n
\u64cd\u4f5c\u7b26<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
-d<\/td>\n\u6d4b\u8bd5\u6587\u4ef6\u662f\u5426\u4e3a\u76ee\u5f55\u7c7b\u578b<\/td>\n<\/tr>\n
-e<\/td>\n\u6d4b\u8bd5\u6587\u4ef6\u662f\u5426\u5b58\u5728<\/td>\n<\/tr>\n
-f<\/td>\n\u5224\u65ad\u662f\u5426\u4e3a\u4e00\u822c\u6587\u4ef6<\/td>\n<\/tr>\n
-r<\/td>\n\u6d4b\u8bd5\u5f53\u524d\u7528\u6237\u662f\u5426\u6709\u6743\u9650\u8bfb\u53d6<\/td>\n<\/tr>\n
-w<\/td>\n\u6d4b\u8bd5\u5f53\u524d\u7528\u6237\u662f\u5426\u6709\u6743\u9650\u5199\u5165<\/td>\n<\/tr>\n
-x<\/td>\n\u6d4b\u8bd5\u5f53\u524d\u7528\u6237\u662f\u5426\u6709\u6743\u9650\u6267\u884c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

\u4e0b\u9762\u4f7f\u7528\u6587\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u6765\u5224\u65ad\/etc\/fstab\u662f\u5426\u4e3a\u4e00\u4e2a\u76ee\u5f55\u7c7b\u578b\u7684\u6587\u4ef6\uff0c\u7136\u540e\u901a\u8fc7Shell\u89e3\u91ca\u5668\u7684\u5185\u8bbe$?\u53d8\u91cf\u663e\u793a\u4e0a\u4e00\u6761\u547d\u4ee4\u6267\u884c\u540e\u7684\u8fd4\u56de\u503c\u3002\u5982\u679c\u8fd4\u56de\u503c\u4e3a0\uff0c\u5219\u76ee\u5f55\u5b58\u5728\uff1b\u5982\u679c\u8fd4\u56de\u503c\u4e3a\u975e\u96f6\u7684\u503c\uff0c\u5219\u610f\u5473\u7740\u76ee\u5f55\u4e0d\u5b58\u5728\uff1a<\/p>\n

[root@linuxprobe ~]# [ -d \/etc\/fstab ]\r\n[root@linuxprobe ~]# echo $?\r\n1\r\n<\/pre>\n

\u518d\u4f7f\u7528\u6587\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u6765\u5224\u65ad\/etc\/fstab\u662f\u5426\u4e3a\u4e00\u822c\u6587\u4ef6\uff0c\u5982\u679c\u8fd4\u56de\u503c\u4e3a0\uff0c\u5219\u4ee3\u8868\u6587\u4ef6\u5b58\u5728\uff0c\u4e14\u4e3a\u4e00\u822c\u6587\u4ef6\uff1a<\/p>\n

[root@linuxprobe ~]# [ -f \/etc\/fstab ]\r\n[root@linuxprobe ~]# echo $?\r\n0\r\n<\/pre>\n

\u903b\u8f91\u8bed\u53e5\u7528\u4e8e\u5bf9\u6d4b\u8bd5\u7ed3\u679c\u8fdb\u884c\u903b\u8f91\u5206\u6790\uff0c\u6839\u636e\u6d4b\u8bd5\u7ed3\u679c\u53ef\u5b9e\u73b0\u4e0d\u540c\u7684\u6548\u679c\u3002\u4f8b\u5982\u5728Shell\u7ec8\u7aef\u4e2d\u903b\u8f91\u201c\u4e0e\u201d\u7684\u8fd0\u7b97\u7b26\u53f7\u662f&&\uff0c\u5b83\u8868\u793a\u5f53\u524d\u9762\u7684\u547d\u4ee4\u6267\u884c\u6210\u529f\u540e\u624d\u4f1a\u6267\u884c\u5b83\u540e\u9762\u7684\u547d\u4ee4\uff0c\u56e0\u6b64\u53ef\u4ee5\u7528\u6765\u5224\u65ad\/dev\/cdrom\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u82e5\u5b58\u5728\u5219\u8f93\u51faExist\u5b57\u6837\u3002<\/p>\n

[root@linuxprobe ~]# [ -e \/dev\/cdrom ] && echo \"Exist\"\r\nExist<\/pre>\n

\u9664\u4e86\u903b\u8f91\u201c\u4e0e\u201d\u5916\uff0c\u8fd8\u6709\u903b\u8f91\u201c\u6216\u201d\uff0c\u5b83\u5728Linux\u7cfb\u7edf\u4e2d\u7684\u8fd0\u7b97\u7b26\u53f7\u4e3a||\uff0c\u8868\u793a\u5f53\u524d\u9762\u7684\u547d\u4ee4\u6267\u884c\u5931\u8d25\u540e\u624d\u4f1a\u6267\u884c\u5b83\u540e\u9762\u7684\u547d\u4ee4\uff0c\u56e0\u6b64\u53ef\u4ee5\u7528\u6765\u7ed3\u5408\u7cfb\u7edf\u73af\u5883\u53d8\u91cfUSER\u6765\u5224\u65ad\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\u662f\u5426\u4e3a\u975e\u7ba1\u7406\u5458\u8eab\u4efd\uff1a<\/p>\n

[root@linuxprobe ~]# echo $USER\r\nroot\r\n[root@linuxprobe ~]# [ $USER = root ] || echo \"user\"\r\n[root@linuxprobe ~]# su - linuxprobe \r\n[linuxprobe@linuxprobe ~]$ [ $USER = root ] || echo \"user\"\r\nuser<\/pre>\n

\u7b2c\u4e09\u79cd\u903b\u8f91\u8bed\u53e5\u662f\u201c\u975e\u201d\uff0c\u5728Linux\u7cfb\u7edf\u4e2d\u7684\u8fd0\u7b97\u7b26\u53f7\u662f\u4e00\u4e2a\u53f9\u53f7\uff08\uff01\uff09\uff0c\u5b83\u8868\u793a\u628a\u6761\u4ef6\u6d4b\u8bd5\u4e2d\u7684\u5224\u65ad\u7ed3\u679c\u53d6\u76f8\u53cd\u503c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5982\u679c\u539f\u672c\u6d4b\u8bd5\u7684\u7ed3\u679c\u662f\u6b63\u786e\u7684\uff0c\u5219\u5c06\u5176\u53d8\u6210\u9519\u8bef\u7684\uff1b\u539f\u672c\u6d4b\u8bd5\u9519\u8bef\u7684\u7ed3\u679c\u5219\u5c06\u5176\u53d8\u6210\u6b63\u786e\u7684\u3002<\/p>\n

\u6211\u4eec\u73b0\u5728\u5207\u6362\u56de\u5230root\u7ba1\u7406\u5458\u8eab\u4efd\uff0c\u518d\u5224\u65ad\u5f53\u524d\u7528\u6237\u662f\u5426\u4e3a\u4e00\u4e2a\u975e\u7ba1\u7406\u5458\u7684\u7528\u6237\u3002\u7531\u4e8e\u5224\u65ad\u7ed3\u679c\u56e0\u4e3a\u4e24\u6b21\u5426\u5b9a\u800c\u53d8\u6210\u6b63\u786e\uff0c\u56e0\u6b64\u4f1a\u6b63\u5e38\u5730\u8f93\u51fa\u9884\u8bbe\u4fe1\u606f\uff1a<\/p>\n

[linuxprobe@linuxprobe ~]$ exit\r\nlogout\r\n[root@linuxprobe root]# [ $USER !<\/strong>= root ] || echo \"administrator\"\r\nadministrator<\/pre>\n

\u5c31\u6280\u672f\u56fe\u4e66\u7684\u5199\u4f5c\u6765\u8bb2\uff0c\u4e00\u822c\u6709\u4e24\u79cd\u5957\u8def\uff1a\u8ba9\u8bfb\u8005\u771f\u6b63\u641e\u61c2\u6280\u672f\u4e86\uff1b\u8ba9\u8bfb\u8005\u89c9\u5f97\u81ea\u5df1\u641e\u61c2\u6280\u672f\u4e86\u3002\u56e0\u6b64\u5e02\u9762\u4e0a\u5f88\u591a\u6d45\u663e\u7684\u56fe\u4e66\u4f1a\u8ba9\u8bfb\u8005\u5728\u5b66\u5b8c\u4e4b\u540e\u611f\u89c9\u8fdb\u6b65\u7279\u522b\u5feb\uff0c\u8fd9\u57fa\u672c\u4e0a\u662f\u4f5c\u8005\u6709\u610f\u4e3a\u4e4b\uff0c\u76ee\u7684\u5c31\u662f\u8ba9\u60a8\u89c9\u5f97\u201c\u56fe\u4e66\u5f88\u6709\u6599\uff0c\u81ea\u5df1\u6536\u83b7\u5f88\u5927\u201d\uff0c\u4f46\u662f\u5728\u6b65\u5165\u5de5\u4f5c\u5c97\u4f4d\u540e\u5c31\u9732\u51fa\u77ed\u677f\u5403\u5927\u4e8f\u3002\u6240\u4ee5\u5218\u9044\u8001\u5e08\u51b3\u5b9a\u7ee7\u7eed\u63d0\u9ad8\u96be\u5ea6\uff0c\u4e3a\u8bfb\u8005\u589e\u52a0\u4e00\u4e2a\u7efc\u5408\u7684\u793a\u4f8b\uff0c\u4e00\u65b9\u9762\u4f5c\u4e3a\u524d\u8ff0\u77e5\u8bc6\u7684\u603b\u7ed3\uff0c\u53e6\u4e00\u65b9\u9762\u5e2e\u52a9\u8bfb\u8005\u592f\u5b9e\u57fa\u7840\uff0c\u80fd\u591f\u5728\u4eca\u540e\u5de5\u4f5c\u4e2d\u66f4\u7075\u6d3b\u5730\u4f7f\u7528\u903b\u8f91\u7b26\u53f7\u3002<\/p>\n

\u5f53\u524d\u6211\u4eec\u6b63\u5728\u767b\u5f55\u7684\u5373\u4e3a\u7ba1\u7406\u5458\u7528\u6237\u2014root\u3002\u4e0b\u9762\u8fd9\u4e2a\u793a\u4f8b\u7684\u6267\u884c\u987a\u5e8f\u662f\uff0c\u5148\u5224\u65ad\u5f53\u524d\u767b\u5f55\u7528\u6237\u7684USER\u53d8\u91cf\u540d\u79f0\u662f\u5426\u7b49\u4e8eroot\uff0c\u7136\u540e\u7528\u903b\u8f91\u8fd0\u7b97\u7b26\u201c\u975e\u201d\u8fdb\u884c\u53d6\u53cd\u64cd\u4f5c\uff0c\u6548\u679c\u5c31\u53d8\u6210\u4e86\u5224\u65ad\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\u662f\u5426\u4e3a\u975e\u7ba1\u7406\u5458\u7528\u6237\u4e86\u3002\u6700\u540e\u82e5\u6761\u4ef6\u6210\u7acb\u5219\u4f1a\u6839\u636e\u903b\u8f91\u201c\u4e0e\u201d\u8fd0\u7b97\u7b26\u8f93\u51fauser\u5b57\u6837\uff1b\u6216\u6761\u4ef6\u4e0d\u6ee1\u8db3\u5219\u4f1a\u901a\u8fc7\u903b\u8f91\u201c\u6216\u201d\u8fd0\u7b97\u7b26\u8f93\u51faroot\u5b57\u6837\uff0c\u800c\u5982\u679c\u524d\u9762\u7684&&\u4e0d\u6210\u7acb\u624d\u4f1a\u6267\u884c\u540e\u9762\u7684||\u7b26\u53f7\u3002<\/p>\n

[root@linuxprobe ~]# [ $USER != root ] && echo \"user\" || echo \"root\"\r\nroot<\/pre>\n
\n

\u6574\u6570\u6bd4\u8f83\u8fd0\u7b97\u7b26\u4ec5\u662f\u5bf9\u6570\u5b57\u7684\u64cd\u4f5c\uff0c\u4e0d\u80fd\u5c06\u6570\u5b57\u4e0e\u5b57\u7b26\u4e32\u3001\u6587\u4ef6\u7b49\u5185\u5bb9\u4e00\u8d77\u64cd\u4f5c\uff0c\u800c\u4e14\u4e0d\u80fd\u60f3\u5f53\u7136\u5730\u4f7f\u7528\u65e5\u5e38\u751f\u6d3b\u4e2d\u7684\u7b49\u53f7\u3001\u5927\u4e8e\u53f7\u3001\u5c0f\u4e8e\u53f7\u7b49\u6765\u5224\u65ad\u3002\u56e0\u4e3a\u7b49\u53f7\u4e0e\u8d4b\u503c\u547d\u4ee4\u7b26\u51b2\u7a81\uff0c\u5927\u4e8e\u53f7\u548c\u5c0f\u4e8e\u53f7\u5206\u522b\u4e0e\u8f93\u51fa\u91cd\u5b9a\u5411\u547d\u4ee4\u7b26\u548c\u8f93\u5165\u91cd\u5b9a\u5411\u547d\u4ee4\u7b26\u51b2\u7a81\u3002\u56e0\u6b64\u4e00\u5b9a\u8981\u4f7f\u7528\u89c4\u8303\u7684\u6574\u6570\u6bd4\u8f83\u8fd0\u7b97\u7b26\u6765\u8fdb\u884c\u64cd\u4f5c\u3002\u53ef\u7528\u7684\u6574\u6570\u6bd4\u8f83\u8fd0\u7b97\u7b26\u5982\u88684-4\u6240\u793a\u3002<\/p>\n

\u88684-4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u53ef\u7528\u7684\u6574\u6570\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/p>\n\n\n\n\n\n\n\n\n\n
\u64cd\u4f5c\u7b26<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
-eq<\/td>\n\u662f\u5426\u7b49\u4e8e<\/td>\n<\/tr>\n
-ne<\/td>\n\u662f\u5426\u4e0d\u7b49\u4e8e<\/td>\n<\/tr>\n
-gt<\/td>\n\u662f\u5426\u5927\u4e8e<\/td>\n<\/tr>\n
-lt<\/td>\n\u662f\u5426\u5c0f\u4e8e<\/td>\n<\/tr>\n
-le<\/td>\n\u662f\u5426\u7b49\u4e8e\u6216\u5c0f\u4e8e<\/td>\n<\/tr>\n
-ge<\/td>\n\u662f\u5426\u5927\u4e8e\u6216\u7b49\u4e8e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

\u63a5\u4e0b\u6765\u5c0f\u8bd5\u725b\u5200\u3002\u6211\u4eec\u5148\u6d4b\u8bd5\u4e00\u4e0b10\u662f\u5426\u5927\u4e8e10\u4ee5\u53ca10\u662f\u5426\u7b49\u4e8e10\uff08\u901a\u8fc7\u8f93\u51fa\u7684\u8fd4\u56de\u503c\u5185\u5bb9\u6765\u5224\u65ad\uff09\uff1a<\/p>\n

[root@linuxprobe ~]# [ 10 -gt 10 ]\r\n[root@linuxprobe ~]# echo $?\r\n1<\/strong>\r\n[root@linuxprobe ~]# [ 10 -eq 10 ]\r\n[root@linuxprobe ~]# echo $?\r\n0\r\n<\/strong><\/pre>\n

\u57282.4\u8282\u66fe\u7ecf\u8bb2\u8fc7free\u547d\u4ee4\uff0c\u5b83\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u6b63\u5728\u4f7f\u7528\u53ca\u53ef\u7528\u7684\u5185\u5b58\u91cf\u4fe1\u606f\u3002\u63a5\u4e0b\u6765\u5148\u4f7f\u7528free -m\u547d\u4ee4\u67e5\u770b\u5185\u5b58\u4f7f\u7528\u91cf\u60c5\u51b5\uff08\u5355\u4f4d\u4e3aMB\uff09\uff0c\u7136\u540e\u901a\u8fc7grep Mem:\u547d\u4ee4\u8fc7\u6ee4\u51fa\u5269\u4f59\u5185\u5b58\u91cf\u7684\u884c\uff0c\u518d\u7528awk '{print $4}'\u547d\u4ee4\u53ea\u4fdd\u7559\u7b2c\u56db\u5217\uff0c\u6700\u540e\u7528FreeMem=`\u8bed\u53e5`\u7684\u65b9\u5f0f\u628a\u8bed\u53e5\u5185\u6267\u884c\u7684\u7ed3\u679c\u8d4b\u503c\u7ed9\u53d8\u91cf\u3002<\/p>\n

\u8fd9\u4e2a\u6f14\u793a\u786e\u5b9e\u6709\u4e9b\u96be\u5ea6\uff0c\u4f46\u770b\u61c2\u540e\u4f1a\u89c9\u5f97\u5f88\u6709\u610f\u601d\uff0c\u6ca1\u51c6\u5728\u8fd0\u7ef4\u5de5\u4f5c\u4e2d\u4e5f\u4f1a\u7528\u5f97\u4e0a\u3002<\/p>\n

[root@linuxprobe ~]# free -m\r\n            total     used     free     shared     buffers     cached\r\nMem:<\/strong>        1826      1244     582<\/strong>      9          1           413\r\n-\/+ buffers\/cache:    830 996\r\nSwap:       2047      0        2047\r\n[root@linuxprobe\u00a0~]# free -m | grep Mem:\r\nMem:        1826      1244     582      9 \r\n[root@linuxprobe\u00a0~]# free -m | grep Mem: | awk '{print $4}'\r\n582\r\n[root@linuxprobe ~]# FreeMem=`free -m | grep Mem: | awk '{print $4}'`\r\n[root@linuxprobe ~]# echo $FreeMem \r\n582\r\n<\/pre>\n

\u4e0a\u9762\u7528\u4e8e\u83b7\u53d6\u5185\u5b58\u53ef\u7528\u91cf\u7684\u547d\u4ee4\u4ee5\u53ca\u6b65\u9aa4\u53ef\u80fd\u6709\u4e9b\u201c\u8d85\u7eb2\u201d\u4e86\uff0c\u5982\u679c\u4e0d\u80fd\u7406\u89e3\u9886\u4f1a\u4e5f\u4e0d\u7528\u62c5\u5fc3\uff0c\u63a5\u4e0b\u6765\u624d\u662f\u91cd\u70b9\u3002\u6211\u4eec\u4f7f\u7528\u6574\u6570\u8fd0\u7b97\u7b26\u6765\u5224\u65ad\u5185\u5b58\u53ef\u7528\u91cf\u7684\u503c\u662f\u5426\u5c0f\u4e8e1024\uff0c\u82e5\u5c0f\u4e8e\u5219\u4f1a\u63d0\u793a\u201cInsufficient Memory\u201d\uff08\u5185\u5b58\u4e0d\u8db3\uff09\u7684\u5b57\u6837\uff1a<\/p>\n

[root@linuxprobe ~]# [ $FreeMem -lt 1024 ] && echo \"Insufficient Memory\"\r\nInsufficient Memory\r\n<\/pre>\n

\u5b57\u7b26\u4e32\u6bd4\u8f83\u8bed\u53e5\u7528\u4e8e\u5224\u65ad\u6d4b\u8bd5\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a\u503c\uff0c\u6216\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u540c\u3002\u5b83\u7ecf\u5e38\u7528\u6765\u5224\u65ad\u67d0\u4e2a\u53d8\u91cf\u662f\u5426\u672a\u88ab\u5b9a\u4e49\uff08\u5373\u5185\u5bb9\u4e3a\u7a7a\u503c\uff09\uff0c\u7406\u89e3\u8d77\u6765\u4e5f\u6bd4\u8f83\u7b80\u5355\u3002\u5b57\u7b26\u4e32\u6bd4\u8f83\u4e2d\u5e38\u89c1\u7684\u8fd0\u7b97\u7b26\u5982\u88684-5\u6240\u793a\u3002<\/p>\n

\u88684-5\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u5e38\u89c1\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/p>\n\n\n\n\n\n\n
\u64cd\u4f5c\u7b26<\/td>\n\u4f5c\u7528<\/td>\n<\/tr>\n
=<\/td>\n\u6bd4\u8f83\u5b57\u7b26\u4e32\u5185\u5bb9\u662f\u5426\u76f8\u540c<\/td>\n<\/tr>\n
!=<\/td>\n\u6bd4\u8f83\u5b57\u7b26\u4e32\u5185\u5bb9\u662f\u5426\u4e0d\u540c<\/td>\n<\/tr>\n
-z<\/td>\n\u5224\u65ad\u5b57\u7b26\u4e32\u5185\u5bb9\u662f\u5426\u4e3a\u7a7a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

\u63a5\u4e0b\u6765\u901a\u8fc7\u5224\u65adString\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\u503c\uff0c\u8fdb\u800c\u5224\u65ad\u662f\u5426\u5b9a\u4e49\u4e86\u8fd9\u4e2a\u53d8\u91cf\uff1a<\/p>\n

[root@linuxprobe ~]# [ -z $String ]\r\n[root@linuxprobe ~]# echo $?\r\n0\r\n<\/pre>\n

\u518d\u5c1d\u8bd5\u5f15\u5165\u903b\u8f91\u8fd0\u7b97\u7b26\u6765\u8bd5\u4e00\u4e0b\u3002\u5f53\u7528\u4e8e\u4fdd\u5b58\u5f53\u524d\u8bed\u7cfb\u7684\u73af\u5883\u53d8\u91cf\u503cLANG\u4e0d\u662f\u82f1\u8bed\uff08en.US\uff09\u65f6\uff0c\u5219\u4f1a\u6ee1\u8db3\u903b\u8f91\u6d4b\u8bd5\u6761\u4ef6\u5e76\u8f93\u51fa\u201cNot en.US\u201d\uff08\u975e\u82f1\u8bed\uff09\u7684\u5b57\u6837\uff1a<\/p>\n

[root@linuxprobe ~]# echo $LANG\r\nen_US.UTF-8\r\n[root@linuxprobe ~]# [ $LANG != \"en.US\" ] && echo \"Not en.US\"\r\nNot en.US\r\n<\/pre>\n

\u51fa\u73b0\u95ee\u9898?\u5927\u80c6\u63d0\u95ee!<\/strong><\/span><\/p>\n

\u56e0\u8bfb\u8005\u4eec\u786c\u4ef6\u4e0d\u540c\u6216\u64cd\u4f5c\u9519\u8bef\u90fd\u53ef\u80fd\u5bfc\u81f4\u5b9e\u9a8c\u914d\u7f6e\u51fa\u9519\uff0c\u8bf7\u8010\u5fc3\u518d\u4ed4\u7ec6\u770b\u770b\u64cd\u4f5c\u6b65\u9aa4\u5427\uff0c\u4e0d\u8981\u6c14\u9981~<\/p>\n

Linux\u6280\u672f\u4ea4\u6d41\u8bf7\u52a0A\u7fa4\uff1a560843(\u6ee1<\/span><\/strong>)\uff0cB\u7fa4\uff1a340829(\u63a8\u8350<\/span><\/strong>)\uff0cC\u7fa4\uff1a463590\uff08\u63a8\u8350<\/span><\/strong>\uff09\uff0c\u70b9\u6b64\u67e5\u770b\u5168\u56fd\u7fa4<\/a>\u3002<\/p>\n

*\u672c\u7fa4\u7279\u8272\uff1a\u901a\u8fc7\u53e3\u4ee4\u9a8c\u8bc1\u786e\u4fdd\u6bcf\u4e00\u4e2a\u7fa4\u5458\u90fd\u662f\u300aLinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b\u7684\u8bfb\u8005\uff0c\u7b54\u7591\u66f4\u6709\u9488\u5bf9\u6027\uff0c\u4e0d\u5b9a\u671f\u514d\u8d39\u9886\u53d6\u5b9a\u5236\u793c\u54c1\u3002<\/p><\/blockquote>\n

4.3 \u6d41\u7a0b\u63a7\u5236\u8bed\u53e5<\/strong><\/span><\/h5>\n

\u5c3d\u7ba1\u6b64\u65f6\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Linux\u547d\u4ee4\u3001\u7ba1\u9053\u7b26\u3001\u91cd\u5b9a\u5411\u4ee5\u53ca\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u6765\u7f16\u5199\u6700\u57fa\u672c\u7684Shell\u811a\u672c\uff0c\u4f46\u662f\u8fd9\u79cd\u811a\u672c\u5e76\u4e0d\u9002\u7528\u4e8e\u751f\u4ea7\u73af\u5883\u3002\u539f\u56e0\u662f\u5b83\u4e0d\u80fd\u6839\u636e\u771f\u5b9e\u7684\u5de5\u4f5c\u9700\u6c42\u6765\u8c03\u6574\u5177\u4f53\u7684\u6267\u884c\u547d\u4ee4\uff0c\u4e5f\u4e0d\u80fd\u6839\u636e\u67d0\u4e9b\u6761\u4ef6\u5b9e\u73b0\u81ea\u52a8\u5faa\u73af\u6267\u884c\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u9700\u8981\u6279\u91cf\u521b\u5efa1000\u4f4d\u7528\u6237\uff0c\u9996\u5148\u8981\u5224\u65ad\u8fd9\u4e9b\u7528\u6237\u662f\u5426\u5df2\u7ecf\u5b58\u5728\uff1b\u82e5\u4e0d\u5b58\u5728\uff0c\u5219\u901a\u8fc7\u5faa\u73af\u8bed\u53e5\u8ba9\u811a\u672c\u81ea\u52a8\u4e14\u4f9d\u6b21\u521b\u5efa\u4ed6\u4eec\u3002<\/p>\n

\u63a5\u4e0b\u6765\u6211\u4eec\u901a\u8fc7if\u3001for\u3001while\u3001case\u8fd94\u79cd\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u6765\u5b66\u4e60\u7f16\u5199\u96be\u5ea6\u66f4\u5927\u3001\u529f\u80fd\u66f4\u5f3a\u7684Shell\u811a\u672c\u3002\u4e3a\u4e86\u4fdd\u8bc1\u4e0b\u6587\u7684\u5b9e\u7528\u6027\u548c\u8da3\u5473\u6027\uff0c\u505a\u5230\u5bd3\u6559\u4e8e\u4e50\uff0c\u6211\u4f1a\u5c3d\u53ef\u80fd\u591a\u5730\u8bb2\u89e3\u5404\u79cd\u4e0d\u540c\u529f\u80fd\u7684Shell\u811a\u672c\u793a\u4f8b\uff0c\u800c\u4e0d\u662f\u902e\u4f4f\u4e00\u4e2a\u811a\u672c\u4e0d\u653e\uff0c\u5728\u5b83\u539f\u6709\u5185\u5bb9\u7684\u57fa\u7840\u4e0a\u4fee\u4fee\u8865\u8865\u3002\u5c3d\u7ba1\u8fd9\u79cd\u4fee\u8865\u5f0f\u7684\u793a\u4f8b\u6559\u5b66\u4e5f\u53ef\u4ee5\u8ba9\u8bfb\u8005\u660e\u767d\u7406\u8bba\u77e5\u8bc6\uff0c\u4f46\u662f\u5374\u65e0\u6cd5\u5f00\u653e\u601d\u8def\uff0c\u4e0d\u5229\u4e8e\u65e5\u540e\u7684\u5de5\u4f5c\u3002<\/p>\n

4.3.1 if\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5<\/strong><\/span><\/h6>\n

if\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u53ef\u4ee5\u8ba9\u811a\u672c\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u81ea\u52a8\u6267\u884c\u76f8\u5e94\u7684\u547d\u4ee4\u3002\u4ece\u6280\u672f\u89d2\u5ea6\u6765\u8bb2\uff0cif\u8bed\u53e5\u5206\u4e3a\u5355\u5206\u652f\u7ed3\u6784\u3001\u53cc\u5206\u652f\u7ed3\u6784\u3001\u591a\u5206\u652f\u7ed3\u6784\uff1b\u5176\u590d\u6742\u5ea6\u968f\u7740\u7075\u6d3b\u5ea6\u4e00\u8d77\u9010\u7ea7\u4e0a\u5347\u3002<\/p>\n

if\u6761\u4ef6\u8bed\u53e5\u7684\u5355\u5206\u652f\u7ed3\u6784\u7531if\u3001then\u3001fi\u5173\u952e\u8bcd\u7ec4\u6210\uff0c\u800c\u4e14\u53ea\u5728\u6761\u4ef6\u6210\u7acb\u540e\u624d\u6267\u884c\u9884\u8bbe\u7684\u547d\u4ee4\uff0c\u76f8\u5f53\u4e8e\u53e3\u8bed\u7684\u201c\u5982\u679c\u2026\u2026\u90a3\u4e48\u2026\u2026\u201d\u3002\u5355\u5206\u652f\u7684if\u8bed\u53e5\u5c5e\u4e8e\u6700\u7b80\u5355\u7684\u4e00\u79cd\u6761\u4ef6\u5224\u65ad\u7ed3\u6784\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u56fe4-17\u6240\u793a\u3002
\n\"%e5%8d%95%e5%88%86%e6%94%af%e7%bb%93%e6%9e%84\"<\/p>\n

\u56fe4-17\u00a0 \u5355\u5206\u652f\u7684if\u8bed\u53e5<\/p>\n

\u4e0b\u9762\u4f7f\u7528\u5355\u5206\u652f\u7684if\u6761\u4ef6\u8bed\u53e5\u6765\u5224\u65ad\/media\/cdrom\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u82e5\u5b58\u5728\u5c31\u7ed3\u675f\u6761\u4ef6\u5224\u65ad\u548c\u6574\u4e2aShell\u811a\u672c\uff0c\u53cd\u4e4b\u5219\u53bb\u521b\u5efa\u8fd9\u4e2a\u76ee\u5f55\uff1a<\/p>\n

[root@linuxprobe ~]# vim mkcdrom.sh\r\n#!\/bin\/bash\r\nDIR=\"\/media\/cdrom\"\r\nif [ ! -e $DIR ]\r\nthen\r\nmkdir -p $DIR\r\nfi\r\n<\/pre>\n

\u7531\u4e8e\u7b2c5\u7ae0\u624d\u8bb2\u89e3\u7528\u6237\u8eab\u4efd\u4e0e\u6743\u9650\uff0c\u56e0\u6b64\u8fd9\u91cc\u7ee7\u7eed\u7528\u201cbash \u811a\u672c\u540d\u79f0\u201d\u7684\u65b9\u5f0f\u6765\u6267\u884c\u811a\u672c\u3002\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u987a\u5229\u6267\u884c\u5b8c\u811a\u672c\u6587\u4ef6\u540e\u6ca1\u6709\u4efb\u4f55\u8f93\u51fa\u4fe1\u606f\uff0c\u4f46\u662f\u53ef\u4ee5\u4f7f\u7528ls\u547d\u4ee4\u9a8c\u8bc1\/media\/cdrom\u76ee\u5f55\u662f\u5426\u5df2\u7ecf\u6210\u529f\u521b\u5efa\uff1a<\/p>\n

[root@linuxprobe ~]# bash mkcdrom.sh\r\n[root@linuxprobe ~]# ls -d \/media\/cdrom\r\n\/media\/cdrom<\/pre>\n
\n

if\u6761\u4ef6\u8bed\u53e5\u7684\u53cc\u5206\u652f\u7ed3\u6784\u7531if\u3001then\u3001else\u3001fi\u5173\u952e\u8bcd\u7ec4\u6210\uff0c\u5b83\u8fdb\u884c\u4e00\u6b21\u6761\u4ef6\u5339\u914d\u5224\u65ad\uff0c\u5982\u679c\u4e0e\u6761\u4ef6\u5339\u914d\uff0c\u5219\u53bb\u6267\u884c\u76f8\u5e94\u7684\u9884\u8bbe\u547d\u4ee4\uff1b\u53cd\u4e4b\u5219\u53bb\u6267\u884c\u4e0d\u5339\u914d\u65f6\u7684\u9884\u8bbe\u547d\u4ee4\uff0c\u76f8\u5f53\u4e8e\u53e3\u8bed\u7684\u201c\u5982\u679c\u2026\u2026\u90a3\u4e48\u2026\u2026\u6216\u8005\u2026\u2026\u90a3\u4e48\u2026\u2026\u201d\u3002if\u6761\u4ef6\u8bed\u53e5\u7684\u53cc\u5206\u652f\u7ed3\u6784\u4e5f\u662f\u4e00\u79cd\u5f88\u7b80\u5355\u7684\u5224\u65ad\u7ed3\u6784\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u56fe4-18\u6240\u793a\u3002<\/p>\n

\"%e5%8f%8c%e5%88%86%e6%94%af%e7%bb%93%e6%9e%84\"<\/p>\n

\u56fe4-18\u00a0\u53cc\u5206\u652f\u7684if\u6761\u4ef6\u8bed\u53e5<\/p>\n

\u4e0b\u9762\u4f7f\u7528\u53cc\u5206\u652f\u7684if\u6761\u4ef6\u8bed\u53e5\u6765\u9a8c\u8bc1\u67d0\u53f0\u4e3b\u673a\u662f\u5426\u5728\u7ebf\uff0c\u7136\u540e\u6839\u636e\u8fd4\u56de\u503c\u7684\u7ed3\u679c\uff0c\u8981\u4e48\u663e\u793a\u4e3b\u673a\u5728\u7ebf\u4fe1\u606f\uff0c\u8981\u4e48\u663e\u793a\u4e3b\u673a\u4e0d\u5728\u7ebf\u4fe1\u606f\u3002\u8fd9\u91cc\u7684\u811a\u672c\u4e3b\u8981\u4f7f\u7528ping\u547d\u4ee4\u6765\u6d4b\u8bd5\u4e0e\u5bf9\u65b9\u4e3b\u673a\u7684\u7f51\u7edc\u8054\u901a\u6027\uff0c\u800cLinux\u7cfb\u7edf\u4e2d\u7684ping\u547d\u4ee4\u4e0d\u50cfWindows\u4e00\u6837\u5c1d\u8bd54\u6b21\u5c31\u7ed3\u675f\uff0c\u56e0\u6b64\u4e3a\u4e86\u907f\u514d\u7528\u6237\u7b49\u5f85\u65f6\u95f4\u8fc7\u957f\uff0c\u9700\u8981\u901a\u8fc7-c\u53c2\u6570\u6765\u89c4\u5b9a\u5c1d\u8bd5\u7684\u6b21\u6570\uff0c\u5e76\u4f7f\u7528-i\u53c2\u6570\u5b9a\u4e49\u6bcf\u4e2a\u6570\u636e\u5305\u7684\u53d1\u9001\u95f4\u9694\uff0c\u4ee5\u53ca\u4f7f\u7528-W\u53c2\u6570\u5b9a\u4e49\u7b49\u5f85\u8d85\u65f6\u65f6\u95f4\u3002<\/p>\n

[root@linuxprobe ~]# vim chkhost.sh\r\n#!\/bin\/bash\r\nping -c 3 -i 0.2 -W 3 $1 &> \/dev\/null\r\nif [ $? -eq 0 ]\r\nthen\r\necho \"Host $1 is On-line.\"\r\nelse\r\necho \"Host $1 is Off-line.\"\r\nfi\r\n<\/pre>\n

\u6211\u4eec\u57284.2.3\u5c0f\u8282\u4e2d\u7528\u8fc7$?\u53d8\u91cf\uff0c\u4f5c\u7528\u662f\u663e\u793a\u4e0a\u4e00\u6b21\u547d\u4ee4\u7684\u6267\u884c\u8fd4\u56de\u503c\u3002\u82e5\u524d\u9762\u7684\u90a3\u6761\u8bed\u53e5\u6210\u529f\u6267\u884c\uff0c\u5219$?\u53d8\u91cf\u4f1a\u663e\u793a\u6570\u5b570\uff0c\u53cd\u4e4b\u5219\u663e\u793a\u4e00\u4e2a\u975e\u96f6\u7684\u6570\u5b57\uff08\u53ef\u80fd\u4e3a1\uff0c\u4e5f\u53ef\u80fd\u4e3a2\uff0c\u53d6\u51b3\u4e8e\u7cfb\u7edf\u7248\u672c\uff09\u3002\u56e0\u6b64\u53ef\u4ee5\u4f7f\u7528\u6574\u6570\u6bd4\u8f83\u8fd0\u7b97\u7b26\u6765\u5224\u65ad$?\u53d8\u91cf\u662f\u5426\u4e3a0\uff0c\u4ece\u800c\u83b7\u77e5\u90a3\u6761\u8bed\u53e5\u7684\u6700\u7ec8\u5224\u65ad\u60c5\u51b5\u3002\u8fd9\u91cc\u7684\u670d\u52a1\u5668IP\u5730\u5740\u4e3a192.168.10.10\uff0c\u6211\u4eec\u6765\u9a8c\u8bc1\u4e00\u4e0b\u811a\u672c\u7684\u6548\u679c\uff1a<\/p>\n

[root@linuxprobe ~]# bash chkhost.sh 192.168.10.10\r\nHost 192.168.10.10 is On-line.\r\n[root@linuxprobe ~]# bash chkhost.sh 192.168.10.20\r\nHost 192.168.10.20 is Off-line.\r\n<\/pre>\n

if\u6761\u4ef6\u8bed\u53e5\u7684\u591a\u5206\u652f\u7ed3\u6784\u7531if\u3001then\u3001else\u3001elif\u3001fi\u5173\u952e\u8bcd\u7ec4\u6210\uff0c\u5b83\u8fdb\u884c\u591a\u6b21\u6761\u4ef6\u5339\u914d\u5224\u65ad\uff0c\u8fd9\u591a\u6b21\u5224\u65ad\u4e2d\u7684\u4efb\u4f55\u4e00\u9879\u5728\u5339\u914d\u6210\u529f\u540e\u90fd\u4f1a\u6267\u884c\u76f8\u5e94\u7684\u9884\u8bbe\u547d\u4ee4\uff0c\u76f8\u5f53\u4e8e\u53e3\u8bed\u7684\u201c\u5982\u679c\u2026\u2026\u90a3\u4e48\u2026\u2026\u5982\u679c\u2026\u2026\u90a3\u4e48\u2026\u2026\u201d\u3002if\u6761\u4ef6\u8bed\u53e5\u7684\u591a\u5206\u652f\u7ed3\u6784\u662f\u5de5\u4f5c\u4e2d\u6700\u5e38\u4f7f\u7528\u7684\u4e00\u79cd\u6761\u4ef6\u5224\u65ad\u7ed3\u6784\uff0c\u5c3d\u7ba1\u76f8\u5bf9\u590d\u6742\u4f46\u662f\u66f4\u52a0\u7075\u6d3b\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u56fe4-19\u6240\u793a\u3002 \"%e5%a4%9a%e5%88%86%e6%94%af%e7%bb%93%e6%9e%84\"<\/p>\n

\u56fe 4-19 \u591a\u5206\u652f\u7684if\u6761\u4ef6\u8bed\u53e5<\/p>\n

\u4e0b\u9762\u4f7f\u7528\u591a\u5206\u652f\u7684if\u6761\u4ef6\u8bed\u53e5\u6765\u5224\u65ad\u7528\u6237\u8f93\u5165\u7684\u5206\u6570\u5728\u54ea\u4e2a\u6210\u7ee9\u533a\u95f4\u5185\uff0c\u7136\u540e\u8f93\u51fa\u5982Excellent\u3001Pass\u3001Fail\u7b49\u63d0\u793a\u4fe1\u606f\u3002\u5728Linux\u7cfb\u7edf\u4e2d\uff0cread\u662f\u7528\u6765\u8bfb\u53d6\u7528\u6237\u8f93\u5165\u4fe1\u606f\u7684\u547d\u4ee4\uff0c\u80fd\u591f\u628a\u63a5\u6536\u5230\u7684\u7528\u6237\u8f93\u5165\u4fe1\u606f\u8d4b\u503c\u7ed9\u540e\u9762\u7684\u6307\u5b9a\u53d8\u91cf\uff0c-p\u53c2\u6570\u7528\u4e8e\u5411\u7528\u6237\u663e\u793a\u4e00\u5b9a\u7684\u63d0\u793a\u4fe1\u606f\u3002\u5728\u4e0b\u9762\u7684\u811a\u672c\u793a\u4f8b\u4e2d\uff0c\u53ea\u6709\u5f53\u7528\u6237\u8f93\u5165\u7684\u5206\u6570\u5927\u4e8e\u7b49\u4e8e85\u5206\u4e14\u5c0f\u4e8e\u7b49\u4e8e100\u5206\uff0c\u624d\u8f93\u51faExcellent\u5b57\u6837\uff1b\u82e5\u5206\u6570\u4e0d\u6ee1\u8db3\u8be5\u6761\u4ef6\uff08\u5373\u5339\u914d\u4e0d\u6210\u529f\uff09\uff0c\u5219\u7ee7\u7eed\u5224\u65ad\u5206\u6570\u662f\u5426\u5927\u4e8e\u7b49\u4e8e70\u5206\u4e14\u5c0f\u4e8e\u7b49\u4e8e84\u5206\uff0c\u5982\u679c\u662f\uff0c\u5219\u8f93\u51faPass\u5b57\u6837\uff1b\u82e5\u4e24\u6b21\u90fd\u843d\u7a7a\uff08\u5373\u4e24\u6b21\u7684\u5339\u914d\u64cd\u4f5c\u90fd\u5931\u8d25\u4e86\uff09\uff0c\u5219\u8f93\u51faFail\u5b57\u6837\uff1a<\/p>\n

[root@linuxprobe ~]# vim chkscore.sh\r\n#!\/bin\/bash\r\nread -p \"Enter your score\uff080-100\uff09\uff1a\" GRADE\r\nif [ $GRADE -ge 85 ] && [ $GRADE -le 100 ] ; then\r\necho \"$GRADE is Excellent\"\r\nelif [ $GRADE -ge 70 ] && [ $GRADE -le 84 ] ; then\r\necho \"$GRADE is Pass\"\r\nelse\r\necho \"$GRADE is Fail\" \r\nfi\r\n[root@linuxprobe ~]# bash chkscore.sh\r\nEnter your score\uff080-100\uff09\uff1a88\r\n88 is Excellent\r\n[root@linuxprobe ~]# bash chkscore.sh \r\nEnter your score\uff080-100\uff09\uff1a80\r\n80 is Pass\r\n<\/pre>\n

\u4e0b\u9762\u6267\u884c\u8be5\u811a\u672c\u3002\u5f53\u7528\u6237\u8f93\u5165\u7684\u5206\u6570\u5206\u522b\u4e3a30\u548c200\u65f6\uff0c\u5176\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n

[root@linuxprobe ~]# bash chkscore.sh\u00a0 \r\nEnter your score\uff080-100\uff09\uff1a30\r\n30 is Fail\r\n[root@linuxprobe ~]# bash chkscore.sh\r\nEnter your score\uff080-100\uff09\uff1a200 \r\n200 is Fail<\/pre>\n

\u4e3a\u4ec0\u4e48\u8f93\u5165\u7684\u5206\u6570\u4e3a200\u65f6\uff0c\u4f9d\u7136\u663e\u793aFail\u5462\uff1f\u539f\u56e0\u5f88\u7b80\u5355\u2014\u6ca1\u6709\u6210\u529f\u5339\u914d\u811a\u672c\u4e2d\u7684\u4e24\u4e2a\u6761\u4ef6\u5224\u65ad\u8bed\u53e5\uff0c\u56e0\u6b64\u81ea\u52a8\u6267\u884c\u4e86\u6700\u7ec8\u7684\u515c\u5e95\u7b56\u7565\u3002\u53ef\u89c1\uff0c\u8fd9\u4e2a\u811a\u672c\u8fd8\u4e0d\u662f\u5f88\u5b8c\u7f8e\uff0c\u5efa\u8bae\u8bfb\u8005\u81ea\u884c\u5b8c\u5584\u8fd9\u4e2a\u811a\u672c\uff0c\u4f7f\u5f97\u7528\u6237\u5728\u8f93\u5165\u5927\u4e8e100\u6216\u5c0f\u4e8e0\u7684\u5206\u6570\u65f6\uff0c\u7ed9\u4e88Error\u62a5\u9519\u5b57\u6837\u7684\u63d0\u793a\u3002<\/p>\n

4.3.2 for\u6761\u4ef6\u5faa\u73af\u8bed\u53e5<\/span><\/strong><\/h6>\n

for\u5faa\u73af\u8bed\u53e5\u5141\u8bb8\u811a\u672c\u4e00\u6b21\u6027\u8bfb\u53d6\u591a\u4e2a\u4fe1\u606f\uff0c\u7136\u540e\u9010\u4e00\u5bf9\u4fe1\u606f\u8fdb\u884c\u64cd\u4f5c\u5904\u7406\uff0c\u5f53\u8981\u5904\u7406\u7684\u6570\u636e\u6709\u8303\u56f4\u65f6\uff0c\u4f7f\u7528for\u5faa\u73af\u8bed\u53e5\u518d\u9002\u5408\u4e0d\u8fc7\u4e86\u3002for\u5faa\u73af\u8bed\u53e5\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u56fe4-20\u6240\u793a\u3002<\/p>\n

\"for%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\"<\/p>\n

\u56fe4-20\u00a0 for\u5faa\u73af\u8bed\u53e5\u7684\u8bed\u6cd5\u683c\u5f0f<\/p>\n

\u4e0b\u9762\u4f7f\u7528for\u5faa\u73af\u8bed\u53e5\u4ece\u5217\u8868\u6587\u4ef6\u4e2d\u8bfb\u53d6\u591a\u4e2a\u7528\u6237\u540d\uff0c\u7136\u540e\u4e3a\u5176\u9010\u4e00\u521b\u5efa\u7528\u6237\u8d26\u6237\u5e76\u8bbe\u7f6e\u5bc6\u7801\u3002\u9996\u5148\u521b\u5efa\u7528\u6237\u540d\u79f0\u7684\u5217\u8868\u6587\u4ef6users.txt\uff0c\u6bcf\u4e2a\u7528\u6237\u540d\u79f0\u5355\u72ec\u4e00\u884c\u3002\u8bfb\u8005\u53ef\u4ee5\u81ea\u884c\u51b3\u5b9a\u5177\u4f53\u7684\u7528\u6237\u540d\u79f0\u548c\u4e2a\u6570\uff1a<\/p>\n

[root@linuxprobe ~]# vim users.txt\r\nandy\r\nbarry\r\ncarl\r\nduke\r\neric\r\ngeorge\r\n<\/pre>\n

\u63a5\u4e0b\u6765\u7f16\u5199Shell\u811a\u672cExample.sh\u3002\u5728\u811a\u672c\u4e2d\u4f7f\u7528read\u547d\u4ee4\u8bfb\u53d6\u7528\u6237\u8f93\u5165\u7684\u5bc6\u7801\u503c\uff0c\u7136\u540e\u8d4b\u503c\u7ed9PASSWD\u53d8\u91cf\uff0c\u5e76\u901a\u8fc7-p\u53c2\u6570\u5411\u7528\u6237\u663e\u793a\u4e00\u6bb5\u63d0\u793a\u4fe1\u606f\uff0c\u544a\u8bc9\u7528\u6237\u6b63\u5728\u8f93\u5165\u7684\u5185\u5bb9\u5373\u5c06\u4f5c\u4e3a\u8d26\u6237\u5bc6\u7801\u3002\u5728\u6267\u884c\u8be5\u811a\u672c\u540e\uff0c\u4f1a\u81ea\u52a8\u4f7f\u7528\u4ece\u5217\u8868\u6587\u4ef6users.txt\u4e2d\u83b7\u53d6\u5230\u6240\u6709\u7684\u7528\u6237\u540d\u79f0\uff0c\u7136\u540e\u9010\u4e00\u4f7f\u7528\u201cid \u7528\u6237\u540d\u201d\u547d\u4ee4\u67e5\u770b\u7528\u6237\u7684\u4fe1\u606f\uff0c\u5e76\u4f7f\u7528$?\u5224\u65ad\u8fd9\u6761\u547d\u4ee4\u662f\u5426\u6267\u884c\u6210\u529f\uff0c\u4e5f\u5c31\u662f\u5224\u65ad\u8be5\u7528\u6237\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u3002<\/p>\n

\u9700\u8981\u591a\u8bf4\u4e00\u53e5\uff0c\/dev\/null\u662f\u4e00\u4e2a\u88ab\u79f0\u4f5cLinux\u9ed1\u6d1e\u7684\u6587\u4ef6\uff0c\u628a\u8f93\u51fa\u4fe1\u606f\u91cd\u5b9a\u5411\u5230\u8fd9\u4e2a\u6587\u4ef6\u7b49\u540c\u4e8e\u5220\u9664\u6570\u636e\uff08\u7c7b\u4f3c\u4e8e\u6ca1\u6709\u56de\u6536\u529f\u80fd\u7684\u5783\u573e\u7bb1\uff09\uff0c\u53ef\u4ee5\u8ba9\u7528\u6237\u7684\u5c4f\u5e55\u7a97\u53e3\u4fdd\u6301\u7b80\u6d01\u3002<\/p>\n

[root@linuxprobe ~]# vim Example.sh\r\n#!\/bin\/bash\r\nread -p \"Enter The Users Password : \" PASSWD\r\nfor UNAME in `cat users.txt`\r\ndo\r\nid $UNAME &> \/dev\/null\r\nif [ $? -eq 0 ]\r\nthen\r\necho \"Already exists\"\r\nelse\r\nuseradd $UNAME &> \/dev\/null\r\necho \"$PASSWD\" | passwd --stdin $UNAME &> \/dev\/null\r\nif [ $? -eq 0 ]\r\nthen\r\necho \"$UNAME , Create success\"\r\nelse\r\necho \"$UNAME ,\u00a0Create failure\"\r\nfi\r\nfi\r\ndone\r\n<\/pre>\n

\u6267\u884c\u6279\u91cf\u521b\u5efa\u7528\u6237\u7684Shell\u811a\u672cExample.sh\uff0c\u5728\u8f93\u5165\u4e3a\u8d26\u6237\u8bbe\u5b9a\u7684\u5bc6\u7801\u540e\u5c06\u7531\u811a\u672c\u81ea\u52a8\u68c0\u67e5\u5e76\u521b\u5efa\u8fd9\u4e9b\u8d26\u6237\u3002\u7531\u4e8e\u5df2\u7ecf\u5c06\u591a\u4f59\u7684\u4fe1\u606f\u901a\u8fc7\u8f93\u51fa\u91cd\u5b9a\u5411\u7b26\u8f6c\u79fb\u5230\u4e86\/dev\/null\u9ed1\u6d1e\u6587\u4ef6\u4e2d\uff0c\u56e0\u6b64\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\u5c4f\u5e55\u7a97\u53e3\u9664\u4e86\u201c\u7528\u6237\u8d26\u6237\u521b\u5efa\u6210\u529f\u201d\uff08Create success\uff09\u7684\u63d0\u793a\u540e\u4e0d\u4f1a\u6709\u5176\u4ed6\u5185\u5bb9\u3002<\/p>\n

\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\/etc\/passwd\u662f\u7528\u6765\u4fdd\u5b58\u7528\u6237\u8d26\u6237\u4fe1\u606f\u7684\u6587\u4ef6\u3002\u5982\u679c\u60f3\u786e\u8ba4\u8fd9\u4e2a\u811a\u672c\u662f\u5426\u6210\u529f\u521b\u5efa\u4e86\u7528\u6237\u8d26\u6237\uff0c\u53ef\u4ee5\u6253\u5f00\u8fd9\u4e2a\u6587\u4ef6\uff0c\u770b\u5176\u4e2d\u662f\u5426\u6709\u8fd9\u4e9b\u65b0\u521b\u5efa\u7684\u7528\u6237\u4fe1\u606f\u3002<\/p>\n

[root@linuxprobe ~]# bash Example.sh\r\nEnter The Users Password : linuxprobe\r\nandy , Create success\r\nbarry , Create success\r\ncarl , Create success\r\nduke , Create success\r\neric , Create success\r\ngeorge , Create success\r\n[root@linuxprobe ~]# tail -6 \/etc\/passwd\r\nandy:x:1001:1001::\/home\/andy:\/bin\/bash\r\nbarry:x:1002:1002::\/home\/barry:\/bin\/bash\r\ncarl:x:1003:1003::\/home\/carl:\/bin\/bash\r\nduke:x:1004:1004::\/home\/duke:\/bin\/bash\r\neric:x:1005:1005::\/home\/eric:\/bin\/bash\r\ngeorge:x:1006:1006::\/home\/george:\/bin\/bash\r\n<\/pre>\n

\u60a8\u8fd8\u8bb0\u5f97\u5728\u5b66\u4e60\u53cc\u5206\u652fif\u6761\u4ef6\u8bed\u53e5\u65f6\uff0c\u7528\u5230\u7684\u90a3\u4e2a\u6d4b\u8bd5\u4e3b\u673a\u662f\u5426\u5728\u7ebf\u7684\u811a\u672c\u4e48\uff1f\u65e2\u7136\u6211\u4eec\u73b0\u5728\u5df2\u7ecf\u638c\u63e1\u4e86for\u5faa\u73af\u8bed\u53e5\uff0c\u4e0d\u59a8\u505a\u4e9b\u66f4\u9177\u7684\u4e8b\u60c5\uff0c\u6bd4\u5982\u5c1d\u8bd5\u8ba9\u811a\u672c\u4ece\u6587\u672c\u4e2d\u81ea\u52a8\u8bfb\u53d6\u4e3b\u673a\u5217\u8868\uff0c\u7136\u540e\u81ea\u52a8\u9010\u4e2a\u6d4b\u8bd5\u8fd9\u4e9b\u4e3b\u673a\u662f\u5426\u5728\u7ebf\u3002<\/p>\n

\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u4e3b\u673a\u5217\u8868\u6587\u4ef6ipadds.txt\uff1a<\/p>\n

[root@linuxprobe ~]# vim\u00a0ipadds.txt\r\n192.168.10.10\r\n192.168.10.11\r\n192.168.10.12\r\n<\/pre>\n

\u7136\u540e\u524d\u9762\u7684\u53cc\u5206\u652fif\u6761\u4ef6\u8bed\u53e5\u4e0efor\u5faa\u73af\u8bed\u53e5\u76f8\u7ed3\u5408\uff0c\u8ba9\u811a\u672c\u4ece\u4e3b\u673a\u5217\u8868\u6587\u4ef6ipadds.txt\u4e2d\u81ea\u52a8\u8bfb\u53d6IP\u5730\u5740\uff08\u7528\u6765\u8868\u793a\u4e3b\u673a\uff09\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9HLIST\u53d8\u91cf\uff0c\u4ece\u800c\u901a\u8fc7\u5224\u65adping\u547d\u4ee4\u6267\u884c\u540e\u7684\u8fd4\u56de\u503c\u6765\u9010\u4e2a\u6d4b\u8bd5\u4e3b\u673a\u662f\u5426\u5728\u7ebf\u3002\u811a\u672c\u4e2d\u51fa\u73b0\u7684$\uff08\u547d\u4ee4\uff09\u662f\u4e00\u79cd\u5b8c\u5168\u7c7b\u4f3c\u4e8e\u7b2c3\u7ae0\u7684\u8f6c\u4e49\u5b57\u7b26\u4e2d\u53cd\u5f15\u53f7`\u547d\u4ee4`\u7684Shell\u64cd\u4f5c\u7b26\uff0c\u6548\u679c\u540c\u6837\u662f\u6267\u884c\u62ec\u53f7\u6216\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u4e32\u4e2d\u7684\u547d\u4ee4\u3002\u5927\u5bb6\u5728\u7f16\u5199\u811a\u672c\u65f6\uff0c\u591a\u5b66\u4e60\u51e0\u79cd\u7c7b\u4f3c\u7684\u65b0\u65b9\u6cd5\uff0c\u53ef\u5728\u5de5\u4f5c\u4e2d\u5927\u663e\u8eab\u624b\uff1a<\/p>\n

[root@linuxprobe\u00a0~]# vim CheckHosts.sh\r\n#!\/bin\/bash\r\nHLIST=$(cat ~\/ipadds.txt)\r\nfor IP in $HLIST\r\ndo\r\nping -c 3 -i 0.2 -W 3 $IP &> \/dev\/null\r\nif [ $? -eq 0 ] ; then\r\necho \"Host $IP is On-line.\"\r\nelse\r\necho \"Host $IP is Off-line.\"\r\nfi\r\ndone\r\n[root@linuxprobe ~]# .\/CheckHosts.sh\r\nHost 192.168.10.10 is On-line.\r\nHost 192.168.10.11 is Off-line.\r\nHost 192.168.10.12 is Off-line.\r\n<\/pre>\n
4.3.3 while\u6761\u4ef6\u5faa\u73af\u8bed\u53e5<\/strong><\/span><\/h6>\n

while\u6761\u4ef6\u5faa\u73af\u8bed\u53e5\u662f\u4e00\u79cd\u8ba9\u811a\u672c\u6839\u636e\u67d0\u4e9b\u6761\u4ef6\u6765\u91cd\u590d\u6267\u884c\u547d\u4ee4\u7684\u8bed\u53e5\uff0c\u5b83\u7684\u5faa\u73af\u7ed3\u6784\u5f80\u5f80\u5728\u6267\u884c\u524d\u5e76\u4e0d\u786e\u5b9a\u6700\u7ec8\u6267\u884c\u7684\u6b21\u6570\uff0c\u5b8c\u5168\u4e0d\u540c\u4e8efor\u5faa\u73af\u8bed\u53e5\u4e2d\u6709\u76ee\u6807\u3001\u6709\u8303\u56f4\u7684\u4f7f\u7528\u573a\u666f\u3002while\u5faa\u73af\u8bed\u53e5\u901a\u8fc7\u5224\u65ad\u6761\u4ef6\u6d4b\u8bd5\u7684\u771f\u5047\u6765\u51b3\u5b9a\u662f\u5426\u7ee7\u7eed\u6267\u884c\u547d\u4ee4\uff0c\u82e5\u6761\u4ef6\u4e3a\u771f\u5c31\u7ee7\u7eed\u6267\u884c\uff0c\u4e3a\u5047\u5c31\u7ed3\u675f\u5faa\u73af\u3002while\u8bed\u53e5\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u56fe4-21\u6240\u793a\u3002 \"while%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\"<\/p>\n

\u56fe4-21\u00a0 while\u5faa\u73af\u8bed\u53e5\u7684\u8bed\u6cd5\u683c\u5f0f<\/p>\n

\u63a5\u4e0b\u6765\u7ed3\u5408\u4f7f\u7528\u591a\u5206\u652f\u7684if\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u4e0ewhile\u6761\u4ef6\u5faa\u73af\u8bed\u53e5\uff0c\u7f16\u5199\u4e00\u4e2a\u7528\u6765\u731c\u6d4b\u6570\u503c\u5927\u5c0f\u7684\u811a\u672cGuess.sh\u3002\u8be5\u811a\u672c\u4f7f\u7528$RANDOM\u53d8\u91cf\u6765\u8c03\u53d6\u51fa\u4e00\u4e2a\u968f\u673a\u7684\u6570\u503c\uff08\u8303\u56f4\u4e3a0\uff5e32767\uff09\uff0c\u5c06\u8fd9\u4e2a\u968f\u673a\u6570\u5bf91000\u8fdb\u884c\u53d6\u4f59\u64cd\u4f5c\uff0c\u5e76\u4f7f\u7528expr\u547d\u4ee4\u53d6\u5f97\u5176\u7ed3\u679c\uff0c\u518d\u7528\u8fd9\u4e2a\u6570\u503c\u4e0e\u7528\u6237\u901a\u8fc7read\u547d\u4ee4\u8f93\u5165\u7684\u6570\u503c\u8fdb\u884c\u6bd4\u8f83\u5224\u65ad\u3002\u8fd9\u4e2a\u5224\u65ad\u8bed\u53e5\u5206\u4e3a\u4e09\u79cd\u60c5\u51b5\uff0c\u5206\u522b\u662f\u5224\u65ad\u7528\u6237\u8f93\u5165\u7684\u6570\u503c\u662f\u7b49\u4e8e\u3001\u5927\u4e8e\u8fd8\u662f\u5c0f\u4e8e\u4f7f\u7528expr\u547d\u4ee4\u53d6\u5f97\u7684\u6570\u503c\u3002\u5f53\u524d\uff0c\u73b0\u5728\u8fd9\u4e9b\u5185\u5bb9\u4e0d\u662f\u91cd\u70b9\uff0c\u6211\u4eec\u5f53\u524d\u8981\u5173\u6ce8\u7684\u662fwhile\u6761\u4ef6\u5faa\u73af\u8bed\u53e5\u4e2d\u7684\u6761\u4ef6\u6d4b\u8bd5\u59cb\u7ec8\u4e3atrue\uff0c\u56e0\u6b64\u5224\u65ad\u8bed\u53e5\u4f1a\u65e0\u9650\u6267\u884c\u4e0b\u53bb\uff0c\u76f4\u5230\u7528\u6237\u8f93\u5165\u7684\u6570\u503c\u7b49\u4e8eexpr\u547d\u4ee4\u53d6\u5f97\u7684\u6570\u503c\u540e\uff0c\u8fd9\u4e24\u8005\u76f8\u7b49\u4e4b\u540e\u624d\u8fd0\u884cexit 0\u547d\u4ee4\uff0c\u7ec8\u6b62\u811a\u672c\u7684\u6267\u884c\u3002<\/p>\n

[root@linuxprobe ~]# vim Guess.sh\r\n#!\/bin\/bash\r\nPRICE=$(expr $RANDOM % 1000)\r\nTIMES=0\r\necho \"\u5546\u54c1\u5b9e\u9645\u4ef7\u683c\u4e3a0-999\u4e4b\u95f4\uff0c\u731c\u731c\u770b\u662f\u591a\u5c11\uff1f\"\r\nwhile true<\/strong>\r\ndo\r\nread -p \"\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a\" INT\r\nlet TIMES++\r\nif [ $INT -eq $PRICE ] ; then\r\necho \"\u606d\u559c\u60a8\u7b54\u5bf9\u4e86\uff0c\u5b9e\u9645\u4ef7\u683c\u662f $PRICE\"\r\necho \"\u60a8\u603b\u5171\u731c\u6d4b\u4e86 $TIMES \u6b21\"\r\nexit 0\r\nelif [ $INT -gt $PRICE ] ; then\r\necho \"\u592a\u9ad8\u4e86\uff01\"\r\nelse\r\necho \"\u592a\u4f4e\u4e86\uff01\"\r\nfi\r\ndone\r\n<\/pre>\n

\u5728\u8fd9\u4e2aGuess.sh\u811a\u672c\u4e2d\uff0c\u6211\u4eec\u6dfb\u52a0\u4e86\u4e00\u4e9b\u4ea4\u4e92\u5f0f\u7684\u4fe1\u606f\uff0c\u4ece\u800c\u4f7f\u5f97\u7528\u6237\u4e0e\u7cfb\u7edf\u7684\u4e92\u52a8\u6027\u5f97\u4ee5\u589e\u5f3a\u3002\u800c\u4e14\u6bcf\u5f53\u5faa\u73af\u5230let TIMES++\u547d\u4ee4\u65f6\u90fd\u4f1a\u8ba9TIMES\u53d8\u91cf\u5185\u7684\u6570\u503c\u52a01\uff0c\u7528\u6765\u7edf\u8ba1\u5faa\u73af\u603b\u8ba1\u6267\u884c\u4e86\u591a\u5c11\u6b21\u3002\u8fd9\u53ef\u4ee5\u8ba9\u7528\u6237\u5f97\u77e5\u603b\u5171\u731c\u6d4b\u4e86\u591a\u5c11\u6b21\u4e4b\u540e\uff0c\u624d\u731c\u5bf9\u4ef7\u683c\u3002<\/p>\n

[root@linuxprobe ~]# bash Guess.sh\r\n\u5546\u54c1\u5b9e\u9645\u4ef7\u683c\u4e3a0-999\u4e4b\u95f4\uff0c\u731c\u731c\u770b\u662f\u591a\u5c11\uff1f\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a500\r\n\u592a\u4f4e\u4e86\uff01\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a800\r\n\u592a\u9ad8\u4e86\uff01\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a650\r\n\u592a\u4f4e\u4e86\uff01\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a720\r\n\u592a\u9ad8\u4e86\uff01\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a690\r\n\u592a\u4f4e\u4e86\uff01\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a700\r\n\u592a\u9ad8\u4e86\uff01\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a695\r\n\u592a\u9ad8\u4e86\uff01\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a692\r\n\u592a\u9ad8\u4e86\uff01\r\n\u8bf7\u8f93\u5165\u60a8\u731c\u6d4b\u7684\u4ef7\u683c\u6570\u76ee\uff1a691\r\n\u606d\u559c\u60a8\u7b54\u5bf9\u4e86\uff0c\u5b9e\u9645\u4ef7\u683c\u662f 691\r\n\u60a8\u603b\u5171\u731c\u6d4b\u4e86 9 \u6b21\r\n<\/pre>\n
4.3.4 case\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5<\/strong><\/span><\/h6>\n

\u5982\u679c\u60a8\u4e4b\u524d\u5b66\u4e60\u8fc7C\u8bed\u8a00\uff0c\u770b\u5230\u8fd9\u4e00\u5c0f\u8282\u7684\u6807\u9898\u80af\u5b9a\u4f1a\u4f1a\u5fc3\u4e00\u7b11\u201c\u8fd9\u4e0d\u5c31\u662fswitch\u8bed\u53e5\u561b\uff01\u201d\u662f\u7684\uff0ccase\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u548cswitch\u8bed\u53e5\u7684\u529f\u80fd\u975e\u5e38\u76f8\u4f3c\uff01case\u8bed\u53e5\u662f\u5728\u591a\u4e2a\u8303\u56f4\u5185\u5339\u914d\u6570\u636e\uff0c\u82e5\u5339\u914d\u6210\u529f\u5219\u6267\u884c\u76f8\u5173\u547d\u4ee4\u5e76\u7ed3\u675f\u6574\u4e2a\u6761\u4ef6\u6d4b\u8bd5\uff1b\u800c\u5982\u679c\u6570\u636e\u4e0d\u5728\u6240\u5217\u51fa\u7684\u8303\u56f4\u5185\uff0c\u5219\u4f1a\u53bb\u6267\u884c\u661f\u53f7\uff08*\uff09\u4e2d\u6240\u5b9a\u4e49\u7684\u9ed8\u8ba4\u547d\u4ee4\u3002case\u8bed\u53e5\u7684\u8bed\u6cd5\u7ed3\u6784\u5982\u56fe4-22\u6240\u793a\u3002<\/p>\n

\"case%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\"<\/p>\n

\u56fe4-22\u00a0 case\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u7684\u8bed\u6cd5\u7ed3\u6784<\/p>\n

\u5728\u524d\u6587\u4ecb\u7ecd\u7684Guess.sh\u811a\u672c\u4e2d\u6709\u4e00\u4e2a\u81f4\u547d\u7684\u5f31\u70b9\u2014\u53ea\u80fd\u63a5\u53d7\u6570\u5b57\uff01\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u8f93\u5165\u4e00\u4e2a\u5b57\u6bcd\uff0c\u4f1a\u53d1\u73b0\u811a\u672c\u7acb\u5373\u5c31\u5d29\u6e83\u4e86\u3002\u539f\u56e0\u662f\u5b57\u6bcd\u65e0\u6cd5\u4e0e\u6570\u5b57\u8fdb\u884c\u5927\u5c0f\u6bd4\u8f83\uff0c\u4f8b\u5982\uff0c\u201ca\u662f\u5426\u5927\u4e8e\u7b49\u4e8e3\u201d\u8fd9\u6837\u7684\u547d\u9898\u662f\u5b8c\u5168\u9519\u8bef\u7684\u3002\u6211\u4eec\u5fc5\u987b\u6709\u4e00\u5b9a\u7684\u63aa\u65bd\u6765\u5224\u65ad\u7528\u6237\u7684\u8f93\u5165\u5185\u5bb9\uff0c\u5f53\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9\u4e0d\u662f\u6570\u5b57\u65f6\uff0c\u811a\u672c\u80fd\u4e88\u4ee5\u63d0\u793a\uff0c\u4ece\u800c\u514d\u4e8e\u5d29\u6e83\u3002<\/p>\n

\u901a\u8fc7\u5728\u811a\u672c\u4e2d\u7ec4\u5408\u4f7f\u7528case\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u548c\u901a\u914d\u7b26\uff08\u8be6\u89c1\u7b2c3\u7ae0\uff09\uff0c\u5b8c\u5168\u53ef\u4ee5\u6ee1\u8db3\u8fd9\u91cc\u7684\u9700\u6c42\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u7f16\u5199\u811a\u672cCheckkeys.sh\uff0c\u63d0\u793a\u7528\u6237\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9\u53d8\u91cfKEY\uff0c\u7136\u540e\u6839\u636e\u53d8\u91cfKEY\u7684\u503c\u5411\u7528\u6237\u663e\u793a\u5176\u503c\u662f\u5b57\u6bcd\u3001\u6570\u5b57\u8fd8\u662f\u5176\u4ed6\u5b57\u7b26\u3002<\/p>\n

[root@linuxprobe ~]# vim Checkkeys.sh\r\n#!\/bin\/bash\r\nread -p \"\u8bf7\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u6309Enter\u952e\u786e\u8ba4\uff1a\" KEY\r\ncase \"$KEY\" in\r\n[a-z]|[A-Z])\r\necho \"\u60a8\u8f93\u5165\u7684\u662f \u5b57\u6bcd\u3002\"\r\n;;\r\n[0-9])\r\necho \"\u60a8\u8f93\u5165\u7684\u662f \u6570\u5b57\u3002\"\r\n;;\r\n*)\r\necho \"\u60a8\u8f93\u5165\u7684\u662f \u7a7a\u683c\u3001\u529f\u80fd\u952e\u6216\u5176\u4ed6\u63a7\u5236\u5b57\u7b26\u3002\"\r\nesac\r\n[root@linuxprobe ~]# bash Checkkeys.sh\r\n\u8bf7\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u6309Enter\u952e\u786e\u8ba4\uff1a6\r\n\u60a8\u8f93\u5165\u7684\u662f \u6570\u5b57\u3002\r\n[root@linuxprobe ~]# bash Checkkeys.sh\r\n\u8bf7\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u6309Enter\u952e\u786e\u8ba4\uff1ap\r\n\u60a8\u8f93\u5165\u7684\u662f \u5b57\u6bcd\u3002\r\n[root@linuxprobe ~]# bash Checkkeys.sh\r\n\u8bf7\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u6309Enter\u952e\u786e\u8ba4\uff1a^[[15~\r\n\u60a8\u8f93\u5165\u7684\u662f \u7a7a\u683c\u3001\u529f\u80fd\u952e\u6216\u5176\u4ed6\u63a7\u5236\u5b57\u7b26\u3002\r\n<\/pre>\n
4.4\u00a0\u8ba1\u5212\u4efb\u52a1\u670d\u52a1\u7a0b\u5e8f<\/strong><\/span><\/h5>\n

\u7ecf\u9a8c\u4e30\u5bcc\u7684\u7cfb\u7edf\u8fd0\u7ef4\u5de5\u7a0b\u5e08\u53ef\u4ee5\u4f7f\u5f97Linux\u5728\u65e0\u9700\u4eba\u4e3a\u4ecb\u5165\u7684\u60c5\u51b5\u4e0b\uff0c\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u6bb5\u81ea\u52a8\u542f\u7528\u6216\u505c\u6b62\u67d0\u4e9b\u670d\u52a1\u6216\u547d\u4ee4\uff0c\u4ece\u800c\u5b9e\u73b0\u8fd0\u7ef4\u7684\u81ea\u52a8\u5316\u3002\u5c3d\u7ba1\u6211\u4eec\u73b0\u5728\u5df2\u7ecf\u6709\u4e86\u529f\u80fd\u5f6a\u608d\u7684\u811a\u672c\u7a0b\u5e8f\u6765\u6267\u884c\u4e00\u4e9b\u6279\u5904\u7406\u5de5\u4f5c\uff0c\u4f46\u662f\uff0c\u5982\u679c\u4ecd\u7136\u9700\u8981\u5728\u6bcf\u5929\u51cc\u6668\u4e24\u70b9\u6572\u51fb\u952e\u76d8\u56de\u8f66\u952e\u6765\u6267\u884c\u8fd9\u4e2a\u811a\u672c\u7a0b\u5e8f\uff0c\u8fd9\u7b80\u76f4\u592a\u75db\u82e6\u4e86\uff08\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u8bad\u7ec3\u60a8\u7684\u5c0f\u732b\u5728\u534a\u591c\u6309\u4e0b\u56de\u8f66\u952e\uff09\u3002\u63a5\u4e0b\u6765\uff0c\u5218\u9044\u8001\u5e08\u5c06\u5411\u5927\u5bb6\u8bb2\u89e3\u5982\u4f55\u8bbe\u7f6e\u670d\u52a1\u5668\u7684\u8ba1\u5212\u4efb\u52a1\u670d\u52a1\uff0c\u628a\u5468\u671f\u6027\u3001\u89c4\u5f8b\u6027\u7684\u5de5\u4f5c\u4ea4\u7ed9\u7cfb\u7edf\u81ea\u52a8\u5b8c\u6210\u3002<\/p>\n

\u8ba1\u5212\u4efb\u52a1\u5206\u4e3a\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\u4e0e\u957f\u671f\u6027\u8ba1\u5212\u4efb\u52a1\uff0c\u5927\u5bb6\u53ef\u4ee5\u6309\u7167\u5982\u4e0b\u65b9\u5f0f\u7406\u89e3\u3002<\/p>\n

\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\uff1a\u4eca\u665a11\u70b930\u5206\u5f00\u542f\u7f51\u7ad9\u670d\u52a1\u3002<\/p>\n

\u957f\u671f\u6027\u8ba1\u5212\u4efb\u52a1\uff1a\u6bcf\u5468\u4e00\u7684\u51cc\u66683\u70b925\u5206\u628a\/home\/wwwroot\u76ee\u5f55\u6253\u5305\u5907\u4efd\u4e3abackup.tar.gz\u3002<\/p><\/blockquote>\n

\u987e\u540d\u601d\u4e49\uff0c\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\u53ea\u6267\u884c\u4e00\u6b21\uff0c\u4e00\u822c\u7528\u4e8e\u6ee1\u8db3\u4e34\u65f6\u7684\u5de5\u4f5c\u9700\u6c42\u3002\u6211\u4eec\u53ef\u4ee5\u7528at\u547d\u4ee4\u5b9e\u73b0\u8fd9\u79cd\u529f\u80fd\uff0c\u53ea\u9700\u8981\u5199\u6210\u201cat \u65f6\u95f4\u201d\u7684\u5f62\u5f0f\u5c31\u53ef\u4ee5\u3002\u5982\u679c\u60f3\u8981\u67e5\u770b\u5df2\u8bbe\u7f6e\u597d\u4f46\u8fd8\u672a\u6267\u884c\u7684\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\uff0c\u53ef\u4ee5\u4f7f\u7528\u201cat -l\u201d\u547d\u4ee4\uff1b\u8981\u60f3\u5c06\u5176\u5220\u9664\uff0c\u53ef\u4ee5\u7528\u201catrm \u4efb\u52a1\u5e8f\u53f7\u201d\u3002\u5728\u4f7f\u7528at\u547d\u4ee4\u6765\u8bbe\u7f6e\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\u65f6\uff0c\u9ed8\u8ba4\u91c7\u7528\u7684\u662f\u4ea4\u4e92\u5f0f\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u4e0b\u8ff0\u547d\u4ee4\u5c06\u7cfb\u7edf\u8bbe\u7f6e\u4e3a\u5728\u4eca\u665a23:30\u5206\u81ea\u52a8\u91cd\u542f\u7f51\u7ad9\u670d\u52a1\u3002<\/p>\n

[root@linuxprobe ~]# at 23:30\r\nat > systemctl restart httpd\r\nat > \u6b64\u5904\u8bf7\u540c\u65f6\u6309\u4e0bCtrl+d\u6765\u7ed3\u675f\u7f16\u5199\u8ba1\u5212\u4efb\u52a1\r\njob 3 at Mon Apr 27 23:30:00 2015\r\n[root@linuxprobe ~]# at -l\r\n3 Mon Apr 27 23:30:00 2016 a root<\/pre>\n

\u5982\u679c\u8bfb\u8005\u60f3\u6311\u6218\u4e00\u4e0b\u96be\u5ea6\u66f4\u5927\u4f46\u7b80\u6377\u6027\u66f4\u9ad8\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u628a\u524d\u9762\u5b66\u4e60\u7684\u7ba1\u9053\u7b26\uff08\u4efb\u610f\u95e8\uff09\u653e\u5230\u4e24\u6761\u547d\u4ee4\u4e4b\u95f4\uff0c\u8ba9at\u547d\u4ee4\u63a5\u6536\u524d\u9762echo\u547d\u4ee4\u7684\u8f93\u51fa\u4fe1\u606f\uff0c\u4ee5\u8fbe\u5230\u901a\u8fc7\u975e\u4ea4\u4e92\u5f0f\u7684\u65b9\u5f0f\u521b\u5efa\u8ba1\u5212\u4e00\u6b21\u6027\u4efb\u52a1\u7684\u76ee\u7684\u3002<\/p>\n

[root@linuxprobe ~]# echo \"systemctl restart httpd\" | at 23:30\r\njob 4 at Mon Apr 27 23:30:00 2015\r\n[root@linuxprobe ~]# at -l\r\n3 Mon Apr 27 23:30:00 2016 a root\r\n4 Mon Apr 27 23:30:00 2016 a root\r\n<\/pre>\n

\u5982\u679c\u6211\u4eec\u4e0d\u5c0f\u5fc3\u8bbe\u7f6e\u4e86\u4e24\u4e2a\u4e00\u6b21\u6027\u8ba1\u5212\u4efb\u52a1\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u8f7b\u677e\u5220\u9664\u5176\u4e2d\u4e00\u4e2a\uff1a<\/p>\n

[root@linuxprobe ~]# atrm 3\r\n[root@linuxprobe ~]# at -l\r\n4 Mon Apr 27 23:30:00 2016 a root<\/pre>\n

\u5982\u679c\u6211\u4eec\u5e0c\u671bLinux\u7cfb\u7edf\u80fd\u591f\u5468\u671f\u6027\u5730\u3001\u6709\u89c4\u5f8b\u5730\u6267\u884c\u67d0\u4e9b\u5177\u4f53\u7684\u4efb\u52a1\uff0c\u90a3\u4e48Linux\u7cfb\u7edf\u4e2d\u9ed8\u8ba4\u542f\u7528\u7684crond\u670d\u52a1\u7b80\u76f4\u518d\u9002\u5408\u4e0d\u8fc7\u4e86\u3002\u521b\u5efa\u3001\u7f16\u8f91\u8ba1\u5212\u4efb\u52a1\u7684\u547d\u4ee4\u4e3a\u201ccrontab -e\u201d\uff0c\u67e5\u770b\u5f53\u524d\u8ba1\u5212\u4efb\u52a1\u7684\u547d\u4ee4\u4e3a\u201ccrontab -l\u201d\uff0c\u5220\u9664\u67d0\u6761\u8ba1\u5212\u4efb\u52a1\u7684\u547d\u4ee4\u4e3a\u201ccrontab -r\u201d\u3002\u53e6\u5916\uff0c\u5982\u679c\u60a8\u662f\u4ee5\u7ba1\u7406\u5458\u7684\u8eab\u4efd\u767b\u5f55\u7684\u7cfb\u7edf\uff0c\u8fd8\u53ef\u4ee5\u5728crontab\u547d\u4ee4\u4e2d\u52a0\u4e0a-u\u53c2\u6570\u6765\u7f16\u8f91\u4ed6\u4eba\u7684\u8ba1\u5212\u4efb\u52a1\u3002<\/p>\n

\u5728\u6b63\u5f0f\u90e8\u7f72\u8ba1\u5212\u4efb\u52a1\u524d\uff0c\u8bf7\u5148\u8ddf\u5218\u9044\u8001\u5e08\u5ff5\u4e00\u4e0b\u53e3\u8bc0\u201c\u5206\u3001\u65f6\u3001\u65e5\u3001\u6708\u3001\u661f\u671f \u547d\u4ee4\u201d\u3002\u8fd9\u662f\u4f7f\u7528crond\u670d\u52a1\u8bbe\u7f6e\u4efb\u52a1\u7684\u53c2\u6570\u683c\u5f0f\uff08\u5176\u683c\u5f0f\u89c1\u88684-6\uff09\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5982\u679c\u6709\u4e9b\u5b57\u6bb5\u6ca1\u6709\u8bbe\u7f6e\uff0c\u5219\u9700\u8981\u4f7f\u7528\u661f\u53f7\uff08*<\/strong>\uff09\u5360\u4f4d\uff0c\u5982\u56fe4-23\u6240\u793a\u3002 \"cron\u8ba1\u5212\u4efb\u52a1\u7684\u53c2\u6570\"<\/p>\n

\u56fe4-23\u00a0 \u4f7f\u7528crond\u8bbe\u7f6e\u4efb\u52a1\u7684\u53c2\u6570\u683c\u5f0f<\/p>\n

\u88684-6\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u4f7f\u7528crond\u8bbe\u7f6e\u4efb\u52a1\u7684\u53c2\u6570\u5b57\u6bb5\u8bf4\u660e<\/p>\n\n\n\n\n\n\n\n\n\n
\u5b57\u6bb5<\/td>\n\u8bf4\u660e<\/td>\n<\/tr>\n
\u5206\u949f<\/td>\n\u53d6\u503c\u4e3a0\uff5e59\u7684\u6574\u6570<\/td>\n<\/tr>\n
\u5c0f\u65f6<\/td>\n\u53d6\u503c\u4e3a0\uff5e23\u7684\u4efb\u610f\u6574\u6570<\/td>\n<\/tr>\n
\u65e5\u671f<\/td>\n\u53d6\u503c\u4e3a1\uff5e31\u7684\u4efb\u610f\u6574\u6570<\/td>\n<\/tr>\n
\u6708\u4efd<\/td>\n\u53d6\u503c\u4e3a1\uff5e12\u7684\u4efb\u610f\u6574\u6570<\/td>\n<\/tr>\n
\u661f\u671f<\/td>\n\u53d6\u503c\u4e3a0\uff5e7\u7684\u4efb\u610f\u6574\u6570\uff0c\u5176\u4e2d0\u4e0e7\u5747\u4e3a\u661f\u671f\u65e5<\/td>\n<\/tr>\n
\u547d\u4ee4<\/td>\n\u8981\u6267\u884c\u7684\u547d\u4ee4\u6216\u7a0b\u5e8f\u811a\u672c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

<\/p>\n

\u5047\u8bbe\u5728\u6bcf\u5468\u4e00\u3001\u4e09\u3001\u4e94\u7684\u51cc\u66683\u70b925\u5206\uff0c\u90fd\u9700\u8981\u4f7f\u7528tar\u547d\u4ee4\u628a\u67d0\u4e2a\u7f51\u7ad9\u7684\u6570\u636e\u76ee\u5f55\u8fdb\u884c\u6253\u5305\u5904\u7406\uff0c\u4f7f\u5176\u4f5c\u4e3a\u4e00\u4e2a\u5907\u4efd\u6587\u4ef6\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528crontab -e\u547d\u4ee4\u6765\u521b\u5efa\u8ba1\u5212\u4efb\u52a1\u3002\u4e3a\u81ea\u5df1\u521b\u5efa\u8ba1\u5212\u4efb\u52a1\u65e0\u9700\u4f7f\u7528-u\u53c2\u6570\uff0c\u5177\u4f53\u7684\u5b9e\u73b0\u6548\u679c\u7684\u53c2\u6570\u5982crontab -l\u547d\u4ee4\u7ed3\u679c\u6240\u793a\uff1a<\/p>\n

[root@linuxprobe ~]# crontab -e\r\nno crontab for root - using an empty one\r\ncrontab: installing new crontab\r\n[root@linuxprobe ~]# crontab -l\r\n25 3 * * 1,3,5 \/usr\/bin\/tar -czvf backup.tar.gz \/home\/wwwroot\r\n<\/strong><\/pre>\n

\u9700\u8981\u8bf4\u660e\u7684\u662f\uff0c\u9664\u4e86\u7528\u9017\u53f7\uff08,\uff09\u6765\u5206\u522b\u8868\u793a\u591a\u4e2a\u65f6\u95f4\u6bb5\uff0c\u4f8b\u5982\u201c8,9,12\u201d\u8868\u793a8\u6708\u30019\u6708\u548c12\u6708\u3002\u8fd8\u53ef\u4ee5\u7528\u51cf\u53f7\uff08-\uff09\u6765\u8868\u793a\u4e00\u6bb5\u8fde\u7eed\u7684\u65f6\u95f4\u5468\u671f\uff08\u4f8b\u5982\u5b57\u6bb5\u201c\u65e5\u201d\u7684\u53d6\u503c\u4e3a\u201c12-15\u201d\uff0c\u5219\u8868\u793a\u6bcf\u6708\u768412\uff5e15\u65e5\uff09\u3002\u4ee5\u53ca\u7528\u9664\u53f7\uff08\/\uff09\u8868\u793a\u6267\u884c\u4efb\u52a1\u7684\u95f4\u9694\u65f6\u95f4\uff08\u4f8b\u5982\u201c*\/2\u201d\u8868\u793a\u6bcf\u96942\u5206\u949f\u6267\u884c\u4e00\u6b21\u4efb\u52a1\uff09\u3002<\/p>\n

\u5982\u679c\u5728crond\u670d\u52a1\u4e2d\u9700\u8981\u540c\u65f6\u5305\u542b\u591a\u6761\u8ba1\u5212\u4efb\u52a1\u7684\u547d\u4ee4\u8bed\u53e5\uff0c\u5e94\u6bcf\u884c\u4ec5\u5199\u4e00\u6761\u3002\u4f8b\u5982\u6211\u4eec\u518d\u6dfb\u52a0\u4e00\u6761\u8ba1\u5212\u4efb\u52a1\uff0c\u5b83\u7684\u529f\u80fd\u662f\u6bcf\u5468\u4e00\u81f3\u5468\u4e94\u7684\u51cc\u66681\u70b9\u949f\u81ea\u52a8\u6e05\u7a7a\/tmp\u76ee\u5f55\u5185\u7684\u6240\u6709\u6587\u4ef6\u3002\u5c24\u5176\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728crond\u670d\u52a1\u7684\u8ba1\u5212\u4efb\u52a1\u53c2\u6570\u4e2d\uff0c\u6240\u6709\u547d\u4ee4\u4e00\u5b9a\u8981\u7528\u7edd\u5bf9\u8def\u5f84\u7684\u65b9\u5f0f\u6765\u5199\uff0c\u5982\u679c\u4e0d\u77e5\u9053\u7edd\u5bf9\u8def\u5f84\uff0c\u8bf7\u7528whereis\u547d\u4ee4\u8fdb\u884c\u67e5\u8be2\uff0crm\u547d\u4ee4\u8def\u5f84\u4e3a\u4e0b\u9762\u8f93\u51fa\u4fe1\u606f\u4e2d\u52a0\u7c97\u90e8\u5206\u3002<\/p>\n

[root@linuxprobe ~]# whereis rm\r\nrm: \/usr\/bin\/rm<\/strong> \/usr\/share\/man\/man1\/rm.1.gz \/usr\/share\/man\/man1p\/rm.1p.gz\r\n[root@linuxprobe ~]# crontab -e\r\ncrontab: installing new crontab\r\n[root@linuxprobe ~]# crontab -l\r\n25 3 * * 1,3,5 \/usr\/bin\/tar -czvf backup.tar.gz \/home\/wwwroot\r\n0 1\u00a0* * 1-5 \/usr\/bin\/rm -rf \/tmp\/*\r\n<\/strong><\/pre>\n

\u5728\u672c\u8282\u6700\u540e\uff0c\u5218\u9044\u8001\u5e08\u518d\u6765\u5570\u55e6\u51e0\u53e5\u5728\u5de5\u4f5c\u4e2d\u4f7f\u7528\u8ba1\u5212\u670d\u52a1\u7684\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n

\u5728crond\u670d\u52a1\u7684\u914d\u7f6e\u53c2\u6570\u4e2d\uff0c\u53ef\u4ee5\u50cfShell\u811a\u672c\u90a3\u6837\u4ee5#\u53f7\u5f00\u5934\u5199\u4e0a\u6ce8\u91ca\u4fe1\u606f\uff0c\u8fd9\u6837\u5728\u65e5\u540e\u56de\u987e\u8fd9\u6bb5\u547d\u4ee4\u4ee3\u7801\u65f6\u53ef\u4ee5\u5feb\u901f\u4e86\u89e3\u5176\u529f\u80fd\u3001\u9700\u6c42\u4ee5\u53ca\u7f16\u5199\u4eba\u5458\u7b49\u91cd\u8981\u4fe1\u606f\u3002<\/p>\n

\u8ba1\u5212\u4efb\u52a1\u4e2d\u7684\u201c\u5206\u201d\u5b57\u6bb5\u5fc5\u987b\u6709\u6570\u503c\uff0c\u7edd\u5bf9\u4e0d\u80fd\u4e3a\u7a7a\u6216\u662f*\u53f7\uff0c\u800c\u201c\u65e5\u201d\u548c\u201c\u661f\u671f\u201d\u5b57\u6bb5\u4e0d\u80fd\u540c\u65f6\u4f7f\u7528\uff0c\u5426\u5219\u5c31\u4f1a\u53d1\u751f\u51b2\u7a81\u3002<\/p><\/blockquote>\n

\u6700\u540e\u518d\u5570\u55e6\u4e00\u53e5\uff0c\u60f3\u5fc5\u8bfb\u8005\u4e5f\u5df2\u7ecf\u53d1\u73b0\u4e86\uff0c\u8bf8\u5982crond\u5728\u5185\u7684\u5f88\u591a\u670d\u52a1\u9ed8\u8ba4\u8c03\u7528\u7684\u662fVim\u7f16\u8f91\u5668\uff0c\u76f8\u4fe1\u5927\u5bb6\u73b0\u5728\u80fd\u8fdb\u4e00\u6b65\u4f53\u4f1a\u5230\u5728Linux\u7cfb\u7edf\u4e2d\u638c\u63e1Vim\u6587\u672c\u7f16\u8f91\u5668\u7684\u597d\u5904\u4e86\u5427\u3002\u6240\u4ee5\u8bf7\u5927\u5bb6\u4e00\u5b9a\u8981\u5728\u5f7b\u5e95\u638c\u63e1Vim\u7f16\u7801\u5668\u4e4b\u540e\u518d\u5b66\u4e60\u4e0b\u4e00\u7ae0\u3002<\/p>\n

\u51fa\u73b0\u95ee\u9898?\u5927\u80c6\u63d0\u95ee!<\/strong><\/span><\/p>\n

\u56e0\u8bfb\u8005\u4eec\u786c\u4ef6\u4e0d\u540c\u6216\u64cd\u4f5c\u9519\u8bef\u90fd\u53ef\u80fd\u5bfc\u81f4\u5b9e\u9a8c\u914d\u7f6e\u51fa\u9519\uff0c\u8bf7\u8010\u5fc3\u518d\u4ed4\u7ec6\u770b\u770b\u64cd\u4f5c\u6b65\u9aa4\u5427\uff0c\u4e0d\u8981\u6c14\u9981~<\/p>\n

Linux\u6280\u672f\u4ea4\u6d41\u8bf7\u52a0A\u7fa4\uff1a560843(\u6ee1<\/span><\/strong>)\uff0cB\u7fa4\uff1a340829(\u63a8\u8350<\/span><\/strong>)\uff0cC\u7fa4\uff1a463590\uff08\u63a8\u8350<\/span><\/strong>\uff09\uff0c\u70b9\u6b64\u67e5\u770b\u5168\u56fd\u7fa4<\/a>\u3002<\/p>\n

*\u672c\u7fa4\u7279\u8272\uff1a\u901a\u8fc7\u53e3\u4ee4\u9a8c\u8bc1\u786e\u4fdd\u6bcf\u4e00\u4e2a\u7fa4\u5458\u90fd\u662f\u300aLinux\u5c31\u8be5\u8fd9\u4e48\u5b66\u300b\u7684\u8bfb\u8005\uff0c\u7b54\u7591\u66f4\u6709\u9488\u5bf9\u6027\uff0c\u4e0d\u5b9a\u671f\u514d\u8d39\u9886\u53d6\u5b9a\u5236\u793c\u54c1\u3002<\/p><\/blockquote>\n

\u672c\u7ae0\u8282\u7684\u590d\u4e60\u4f5c\u4e1a<\/span>(\u7b54\u6848\u5c31\u5728\u95ee\u9898\u7684\u4e0b\u4e00\u884c\u54e6\uff0c\u7528\u9f20\u6807\u9009\u4e2d\u5373\u53ef\u770b\u5230\u7684~)<\/strong><\/span><\/p>\n

 <\/p>\n

1\uff0eVim\u7f16\u8f91\u5668\u7684\u4e09\u79cd\u6a21\u5f0f\u5206\u522b\u662f\u4ec0\u4e48\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u547d\u4ee4\u6a21\u5f0f\u3001\u672b\u884c\u6a21\u5f0f\u4e0e\u8f93\u5165\u6a21\u5f0f\uff08\u4e5f\u53eb\u7f16\u8f91\u6a21\u5f0f\u6216\u63d2\u5165\u6a21\u5f0f\uff09\u3002<\/span><\/p>\n

2\uff0e\u600e\u4e48\u4ece\u8f93\u5165\u6a21\u5f0f\u5207\u6362\u5230\u672b\u884c\u6a21\u5f0f\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u9700\u8981\u5148\u6572\u51fbEsc\u952e\u9000\u56de\u5230\u547d\u4ee4\u6a21\u5f0f\uff0c\u7136\u540e\u6572\u51fb\u5192\u53f7\uff08:\uff09\u952e\u540e\u8fdb\u5165\u672b\u884c\u6a21\u5f0f\u3002<\/span><\/p>\n

3\uff0e\u4e00\u4e2a\u5b8c\u6574\u7684Shell\u811a\u672c\u5e94\u8be5\u54ea\u4e9b\u5185\u5bb9\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u5e94\u8be5\u5305\u62ec\u811a\u672c\u58f0\u660e\u3001\u6ce8\u91ca\u4fe1\u606f\u548c\u53ef\u6267\u884c\u8bed\u53e5\uff08\u5373\u547d\u4ee4\uff09\u3002<\/span><\/p>\n

4\uff0e\u5206\u522b\u89e3\u91caShell\u811a\u672c\u4e2d$0\u4e0e$3\u53d8\u91cf\u7684\u4f5c\u7528\u3002<\/p>\n

\u7b54\uff1a<\/strong>\u5728Shell\u811a\u672c\u4e2d\uff0c$0\u4ee3\u8868\u811a\u672c\u6587\u4ef6\u7684\u540d\u79f0\uff0c$3\u5219\u4ee3\u8868\u8be5\u811a\u672c\u5728\u6267\u884c\u65f6\u63a5\u6536\u7684\u7b2c\u4e09\u4e2a\u53c2\u6570\u3002<\/span><\/p>\n

5\uff0eif\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u6709\u51e0\u79cd\u7ed3\u6784\uff0c\u6700\u7075\u6d3b\u4e14\u6700\u590d\u6742\u7684\u662f\u54ea\u79cd\u7ed3\u6784\uff1f<\/p>\n

\u7b54\uff1a<\/strong>if\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u5305\u62ec\u5355\u5206\u652f\u3001\u53cc\u5206\u652f\u4e0e\u591a\u5206\u652f\u7b49\u4e09\u79cd\u7ed3\u6784\uff0c\u5176\u4e2d\u591a\u5206\u652f\u7ed3\u6784\u662f\u6700\u7075\u6d3b\u4e14\u6700\u590d\u6742\u7684\u7ed3\u6784\uff0c\u5176\u7ed3\u6784\u5f62\u5f0f\u4e3aif\u2026then\u2026elif\u2026then\u2026else\u2026fi\u3002<\/span><\/p>\n

6\uff0efor\u6761\u4ef6\u5faa\u73af\u8bed\u53e5\u7684\u5faa\u73af\u7ed3\u6784\u662f\u4ec0\u4e48\u6837\u5b50\u7684\uff1f<\/p>\n

\u7b54\uff1a<\/strong>for\u6761\u4ef6\u5faa\u73af\u8bed\u53e5\u7684\u7ed3\u6784\u4e3a\u201cfor \u53d8\u91cf\u540d in \u53d6\u503c\u5217\u8868 do \u547d\u4ee4\u5e8f\u5217 done\u201d\uff0c\u5982\u56fe4-20\u6240\u793a\u3002<\/span><\/p>\n

7\uff0e\u82e5\u5728while\u6761\u4ef6\u5faa\u73af\u8bed\u53e5\u4e2d\u4f7f\u7528true\u4f5c\u4e3a\u5faa\u73af\u6761\u4ef6\uff0c\u90a3\u4e48\u4f1a\u53d1\u751f\u4ec0\u4e48\u4e8b\u60c5\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u56e0\u6761\u4ef6\u6d4b\u8bd5\u503c\u6c38\u4e45\u4e3atrue\uff0c\u56e0\u6b64\u811a\u672c\u4e2d\u5faa\u73af\u90e8\u5206\u4f1a\u65e0\u9650\u5730\u91cd\u590d\u6267\u884c\u4e0b\u53bb\uff0c\u76f4\u5230\u78b0\u5230exit\u547d\u4ee4\u624d\u4f1a\u7ed3\u675f\u3002<\/span><\/p>\n

8\uff0e\u5982\u679c\u9700\u8981\u4f9d\u636e\u7528\u6237\u7684\u8f93\u5165\u53c2\u6570\u6267\u884c\u4e0d\u540c\u7684\u64cd\u4f5c\uff0c\u6700\u65b9\u4fbf\u7684\u6761\u4ef6\u6d4b\u8bd5\u8bed\u53e5\u662f\u4ec0\u4e48\uff1f<\/p>\n

\u7b54\uff1a<\/strong>case\u6761\u4ef6\u8bed\u53e5\u3002<\/span><\/p>\n

9\uff0eLinux\u7cfb\u7edf\u7684\u957f\u671f\u8ba1\u5212\u4efb\u52a1\u6240\u4f7f\u7528\u7684\u670d\u52a1\u662f\u4ec0\u4e48\uff0c\u5176\u53c2\u6570\u683c\u5f0f\u662f\u4ec0\u4e48\uff1f<\/p>\n

\u7b54\uff1a<\/strong>\u957f\u671f\u8ba1\u5212\u4efb\u52a1\u9700\u8981\u4f7f\u7528crond\u670d\u52a1\u7a0b\u5e8f\uff0c\u53c2\u6570\u683c\u5f0f\u662f\u201c\u5206\u3001\u65f6\u3001\u65e5\u3001\u6708\u3001\u661f\u671f \u547d\u4ee4\u201d\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

\u7ea2\u5e3d\u67b6\u6784\u5e08\u4ece0\u57fa\u7840\u6559\u4f1a\u60a8\u7528im\u7f16\u8f91\u5668\u6765\u7f16\u5199\u6587\u6863\u3001\u914d\u7f6e\u4e3b\u673a\u540d\u79f0\u3001\u7f51\u5361\u53c2\u6570\u4ee5\u53cayum\u4ed3\u5e93\u7b49\uff0c\u8bb2\u8ff0Shell\u811a\u672c\u7684\u903b\u8f91\u6d4b\u8bd5\u8bed\u53e5\uff08if\u3001for\u3001while\u3001case)\uff0c\u4f7f\u7528at\u547d\u4ee4\u6216crontab\u8ba1\u5212\u4efb\u52a1\u670d\u52a1\u8ba9\u65e5\u5e38\u5de5\u4f5c\u66f4\u52a0\u7684\u9ad8\u6548\u81ea\u52a8\u5316\uff0c\u4e00\u52b3\u6c38\u9038\u54e6~<\/p>\n","protected":false},"author":1,"featured_media":12598,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[558],"tags":[],"class_list":["post-1498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-rhel7"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/1498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=1498"}],"version-history":[{"count":166,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/1498\/revisions"}],"predecessor-version":[{"id":218012,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/1498\/revisions\/218012"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/12598"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=1498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=1498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=1498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}