{"id":109,"date":"2025-06-24T15:07:23","date_gmt":"2025-06-24T07:07:23","guid":{"rendered":"http:\/\/1.14.207.80\/?p=109"},"modified":"2025-06-24T15:24:29","modified_gmt":"2025-06-24T07:24:29","slug":"linux%e5%9f%ba%e7%a1%80%ef%bc%88%e4%bf%a1%e5%8f%b7%e3%80%81%e5%8f%98%e9%87%8f%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.zhangjianjia.xyz\/index.php\/2025\/06\/24\/linux%e5%9f%ba%e7%a1%80%ef%bc%88%e4%bf%a1%e5%8f%b7%e3%80%81%e5%8f%98%e9%87%8f%ef%bc%89\/","title":{"rendered":"Linux\u57fa\u7840\uff08\u4fe1\u53f7\u3001\u53d8\u91cf\uff09"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><h1>Shell \u811a\u672c\u9ad8\u7ea7\u7279\u6027\u5b8c\u5168\u6307\u5357<\/h1>\n<h2>\u4fe1\u53f7\u4e0e\u4fe1\u53f7\u6355\u6349\u5de5\u5177 trap<\/h2>\n<h3>\u4fe1\u53f7\u6982\u8ff0<\/h3>\n<p>\u4fe1\u53f7\u662f\u64cd\u4f5c\u7cfb\u7edf\u4e0e\u8fd0\u884c\u7a0b\u5e8f\u901a\u4fe1\u7684\u673a\u5236\uff0c\u7528\u4e8e\u54cd\u5e94\u7279\u5b9a\u4e8b\u4ef6\uff1a<\/p>\n<ul>\n<li>\u7528\u6237\u6309\u4e0b <code>Ctrl+C<\/code> \u65f6\u53d1\u9001 <strong>SIGINT<\/strong> \u4fe1\u53f7<\/li>\n<li><code>kill<\/code> \u547d\u4ee4\u9ed8\u8ba4\u53d1\u9001 <strong>SIGTERM<\/strong> \u4fe1\u53f7<\/li>\n<li>\u7cfb\u7edf\u5f02\u5e38\u65f6\u81ea\u52a8\u53d1\u9001\u7279\u5b9a\u4fe1\u53f7<\/li>\n<\/ul>\n<h3>\u4fe1\u53f7\u5217\u8868 (64\u4e2a\u4fe1\u53f7)<\/h3>\n<h4>\u4f20\u7edf\u4fe1\u53f7 (1-31\u53f7)<\/h4>\n<table>\n<thead>\n<tr>\n<th>\u7f16\u53f7<\/th>\n<th>\u4fe1\u53f7\u540d<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td><strong>SIGHUP<\/strong><\/td>\n<td>\u7ec8\u7aef\u6302\u8d77\u6216\u63a7\u5236\u8fdb\u7a0b\u7ec8\u6b62<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><strong>SIGINT<\/strong><\/td>\n<td>\u4e2d\u65ad\u8fdb\u7a0b\uff08\u901a\u5e38\u7531 Ctrl+C \u4ea7\u751f\uff09<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td><strong>SIGQUIT<\/strong><\/td>\n<td>\u9000\u51fa\u8fdb\u7a0b\u5e76\u751f\u6210\u6838\u5fc3\u8f6c\u50a8\u6587\u4ef6\uff08\u901a\u5e38\u7531 Ctrl+\\ \u4ea7\u751f\uff09<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td><strong>SIGILL<\/strong><\/td>\n<td>\u975e\u6cd5\u6307\u4ee4<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td><strong>SIGTRAP<\/strong><\/td>\n<td>\u8ddf\u8e2a\/\u65ad\u70b9\u9677\u9631<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td><strong>SIGABRT<\/strong><\/td>\n<td>\u7531 abort(3) \u4ea7\u751f\u7684\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td><strong>SIGBUS<\/strong><\/td>\n<td>\u603b\u7ebf\u9519\u8bef\uff08\u975e\u6cd5\u7684\u5185\u5b58\u5730\u5740\uff09<\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td><strong>SIGFPE<\/strong><\/td>\n<td>\u7b97\u672f\u5f02\u5e38\uff08\u5982\u9664\u96f6\u9519\u8bef\uff09<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td><strong>SIGKILL<\/strong><\/td>\n<td><strong>\u7acb\u5373\u6740\u6b7b\u8fdb\u7a0b\uff08\u4e0d\u80fd\u88ab\u6355\u83b7\u3001\u963b\u585e\u6216\u5ffd\u7565\uff09<\/strong><\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td><strong>SIGUSR1<\/strong><\/td>\n<td>\u7528\u6237\u5b9a\u4e49\u7684\u4fe1\u53f7 1<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td><strong>SIGSEGV<\/strong><\/td>\n<td>\u6bb5\u9519\u8bef\uff08\u975e\u6cd5\u7684\u5185\u5b58\u8bbf\u95ee\uff09<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td><strong>SIGUSR2<\/strong><\/td>\n<td>\u7528\u6237\u5b9a\u4e49\u7684\u4fe1\u53f7 2<\/td>\n<\/tr>\n<tr>\n<td>13<\/td>\n<td><strong>SIGPIPE<\/strong><\/td>\n<td>\u7ba1\u9053\u7834\u88c2\uff08\u5411\u6ca1\u6709\u8bfb\u7aef\u7684\u7ba1\u9053\u5199\u6570\u636e\uff09<\/td>\n<\/tr>\n<tr>\n<td>14<\/td>\n<td><strong>SIGALRM<\/strong><\/td>\n<td>\u95f9\u949f\u4fe1\u53f7\uff08\u7531 alarm(2) \u4ea7\u751f\u7684\u4fe1\u53f7\uff09<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td><strong>SIGTERM<\/strong><\/td>\n<td>\u7ec8\u6b62\u8fdb\u7a0b\uff08\u8bf7\u6c42\u8fdb\u7a0b\u7ec8\u6b62\uff09<\/td>\n<\/tr>\n<tr>\n<td>16<\/td>\n<td><strong>SIGSTKFLT<\/strong><\/td>\n<td>\u534f\u5904\u7406\u5668\u6808\u9519\u8bef<\/td>\n<\/tr>\n<tr>\n<td>17<\/td>\n<td><strong>SIGCHLD<\/strong><\/td>\n<td>\u5b50\u8fdb\u7a0b\u72b6\u6001\u6539\u53d8\uff08\u5b50\u8fdb\u7a0b\u505c\u6b62\u6216\u9000\u51fa\uff09<\/td>\n<\/tr>\n<tr>\n<td>18<\/td>\n<td><strong>SIGCONT<\/strong><\/td>\n<td>\u7ee7\u7eed\u6267\u884c\u88ab\u505c\u6b62\u7684\u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td>19<\/td>\n<td><strong>SIGSTOP<\/strong><\/td>\n<td><strong>\u505c\u6b62\u8fdb\u7a0b\u7684\u6267\u884c\uff08\u4e0d\u80fd\u88ab\u6355\u83b7\u3001\u963b\u585e\u6216\u5ffd\u7565\uff09<\/strong><\/td>\n<\/tr>\n<tr>\n<td>20<\/td>\n<td><strong>SIGTSTP<\/strong><\/td>\n<td>\u505c\u6b62\u8fdb\u7a0b\u7684\u6267\u884c\uff08\u901a\u5e38\u7531 Ctrl+Z \u4ea7\u751f\uff09<\/td>\n<\/tr>\n<tr>\n<td>21<\/td>\n<td><strong>SIGTTIN<\/strong><\/td>\n<td>\u540e\u53f0\u8fdb\u7a0b\u8bd5\u56fe\u4ece\u63a7\u5236\u7ec8\u7aef\u8bfb\u53d6<\/td>\n<\/tr>\n<tr>\n<td>22<\/td>\n<td><strong>SIGTTOU<\/strong><\/td>\n<td>\u540e\u53f0\u8fdb\u7a0b\u8bd5\u56fe\u5411\u63a7\u5236\u7ec8\u7aef\u5199\u5165<\/td>\n<\/tr>\n<tr>\n<td>23<\/td>\n<td><strong>SIGURG<\/strong><\/td>\n<td>\u5957\u63a5\u5b57\u4e0a\u6709\u7d27\u6025\u6570\u636e\u53ef\u8bfb<\/td>\n<\/tr>\n<tr>\n<td>24<\/td>\n<td><strong>SIGXCPU<\/strong><\/td>\n<td>CPU \u65f6\u95f4\u9650\u5236\u8d85\u65f6<\/td>\n<\/tr>\n<tr>\n<td>25<\/td>\n<td><strong>SIGXFSZ<\/strong><\/td>\n<td>\u6587\u4ef6\u5927\u5c0f\u9650\u5236\u8d85\u65f6<\/td>\n<\/tr>\n<tr>\n<td>26<\/td>\n<td><strong>SIGVTALRM<\/strong><\/td>\n<td>\u865a\u62df\u5b9a\u65f6\u5668\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>27<\/td>\n<td><strong>SIGPROF<\/strong><\/td>\n<td>\u5256\u6790\u5b9a\u65f6\u5668\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>28<\/td>\n<td><strong>SIGWINCH<\/strong><\/td>\n<td>\u7a97\u53e3\u5927\u5c0f\u6539\u53d8<\/td>\n<\/tr>\n<tr>\n<td>29<\/td>\n<td><strong>SIGIO<\/strong><\/td>\n<td>I\/O \u53ef\u80fd\u4e8b\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>30<\/td>\n<td><strong>SIGPWR<\/strong><\/td>\n<td>\u7535\u6e90\u6545\u969c\uff08\u91cd\u542f\uff09<\/td>\n<\/tr>\n<tr>\n<td>31<\/td>\n<td><strong>SIGSYS<\/strong><\/td>\n<td>\u975e\u6cd5\u7684\u7cfb\u7edf\u8c03\u7528\uff08SVID \u6269\u5c55\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u5b9e\u65f6\u4fe1\u53f7 (34-64\u53f7)<\/h4>\n<table>\n<thead>\n<tr>\n<th>\u7f16\u53f7<\/th>\n<th>\u4fe1\u53f7\u540d<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>34<\/td>\n<td><strong>SIGRTMIN<\/strong><\/td>\n<td>\u5b9e\u65f6\u4fe1\u53f7\u6700\u5c0f\u503c\uff08\u7528\u6237\u81ea\u5b9a\u4e49\uff09<\/td>\n<\/tr>\n<tr>\n<td>35<\/td>\n<td><strong>SIGRTMIN+1<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>36<\/td>\n<td><strong>SIGRTMIN+2<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>37<\/td>\n<td><strong>SIGRTMIN+3<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>38<\/td>\n<td><strong>SIGRTMIN+4<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>39<\/td>\n<td><strong>SIGRTMIN+5<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>40<\/td>\n<td><strong>SIGRTMIN+6<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>41<\/td>\n<td><strong>SIGRTMIN+7<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>42<\/td>\n<td><strong>SIGRTMIN+8<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>43<\/td>\n<td><strong>SIGRTMIN+9<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>44<\/td>\n<td><strong>SIGRTMIN+10<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>45<\/td>\n<td><strong>SIGRTMIN+11<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>46<\/td>\n<td><strong>SIGRTMIN+12<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>47<\/td>\n<td><strong>SIGRTMIN+13<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>48<\/td>\n<td><strong>SIGRTMIN+14<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>49<\/td>\n<td><strong>SIGRTMIN+15<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>50<\/td>\n<td><strong>SIGRTMAX-14<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>51<\/td>\n<td><strong>SIGRTMAX-13<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>52<\/td>\n<td><strong>SIGRTMAX-12<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>53<\/td>\n<td><strong>SIGRTMAX-11<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>54<\/td>\n<td><strong>SIGRTMAX-10<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>55<\/td>\n<td><strong>SIGRTMAX-9<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>56<\/td>\n<td><strong>SIGRTMAX-8<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>57<\/td>\n<td><strong>SIGRTMAX-7<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>58<\/td>\n<td><strong>SIGRTMAX-6<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>59<\/td>\n<td><strong>SIGRTMAX-5<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>60<\/td>\n<td><strong>SIGRTMAX-4<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>61<\/td>\n<td><strong>SIGRTMAX-3<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>62<\/td>\n<td><strong>SIGRTMAX-2<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>63<\/td>\n<td><strong>SIGRTMAX-1<\/strong><\/td>\n<td>\u7528\u6237\u81ea\u5b9a\u4e49\u5b9e\u65f6\u4fe1\u53f7<\/td>\n<\/tr>\n<tr>\n<td>64<\/td>\n<td><strong>SIGRTMAX<\/strong><\/td>\n<td>\u5b9e\u65f6\u4fe1\u53f7\u6700\u5927\u503c\uff08\u7528\u6237\u81ea\u5b9a\u4e49\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote>\n<p><strong>\u91cd\u8981\u63d0\u793a<\/strong>\uff1a<\/p>\n<ol>\n<li><strong>SIGKILL (9)<\/strong> \u548c <strong>SIGSTOP (19)<\/strong> \u4e0d\u80fd\u88ab\u6355\u83b7\u3001\u963b\u585e\u6216\u5ffd\u7565<\/li>\n<li>\u5b9e\u65f6\u4fe1\u53f7\uff0834-64\uff09\u6ca1\u6709\u9884\u5b9a\u4e49\u542b\u4e49\uff0c\u7528\u4e8e\u5e94\u7528\u7a0b\u5e8f\u81ea\u5b9a\u4e49<\/li>\n<li>\u4fe1\u53f7 32 \u548c 33 \u4e3a\u7cfb\u7edf\u4fdd\u7559\uff0c\u672a\u5217\u51fa<\/li>\n<li>\u4f7f\u7528 <code>kill -L<\/code> \u547d\u4ee4\u53ef\u67e5\u770b\u5f53\u524d\u7cfb\u7edf\u7684\u5b8c\u6574\u4fe1\u53f7\u5217\u8868<\/li>\n<\/ol>\n<\/blockquote>\n<h3>trap \u57fa\u672c\u529f\u80fd<\/h3>\n<p>trap \u662f Shell \u811a\u672c\u4e2d\u7528\u4e8e\u6355\u83b7\u548c\u5904\u7406\u4fe1\u53f7\u7684\u5f3a\u5927\u5de5\u5177\uff1a<\/p>\n<ul>\n<li>\u6355\u83b7\u7279\u5b9a\u4fe1\u53f7\u5e76\u6267\u884c\u6307\u5b9a\u64cd\u4f5c<\/li>\n<li>\u5b9e\u73b0\u4f18\u96c5\u9000\u51fa\u548c\u8d44\u6e90\u6e05\u7406<\/li>\n<li>\u5ffd\u7565\u7279\u5b9a\u4fe1\u53f7\u9632\u6b62\u610f\u5916\u4e2d\u65ad<\/li>\n<li>\u8bb0\u5f55\u9519\u8bef\u65e5\u5fd7\u548c\u8bca\u65ad\u4fe1\u606f<\/li>\n<\/ul>\n<h3>\u57fa\u672c\u8bed\u6cd5<\/h3>\n<pre><code class=\"language-bash\">trap command signal [signal ...]\n<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>\u53c2\u6570<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>command<\/code><\/td>\n<td>\u4fe1\u53f7\u53d1\u751f\u65f6\u6267\u884c\u7684\u547d\u4ee4\u6216\u51fd\u6570<\/td>\n<\/tr>\n<tr>\n<td><code>signal<\/code><\/td>\n<td>\u4fe1\u53f7\u540d\uff08\u5927\u5c0f\u5199\u4e0d\u654f\u611f\uff0cSIG\u524d\u7f00\u53ef\u9009\uff09\u6216\u4fe1\u53f7\u6570\u503c<\/td>\n<\/tr>\n<tr>\n<td><code>''<\/code><\/td>\n<td>\u5ffd\u7565\u4fe1\u53f7\uff08\u7a7a\u5b57\u7b26\u4e32\uff09<\/td>\n<\/tr>\n<tr>\n<td><code>-<\/code><\/td>\n<td>\u6062\u590d\u4fe1\u53f7\u7684\u9ed8\u8ba4\u884c\u4e3a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u5e38\u7528\u4fe1\u53f7\u5904\u7406\u573a\u666f<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u4fe1\u53f7<\/th>\n<th>\u5178\u578b\u573a\u666f<\/th>\n<th>\u9ed8\u8ba4\u884c\u4e3a<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>SIGINT<\/strong><\/td>\n<td>\u7528\u6237\u6309\u4e0b Ctrl+C \u4e2d\u65ad\u811a\u672c<\/td>\n<td>\u7ec8\u6b62\u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td><strong>SIGTERM<\/strong><\/td>\n<td>\u7cfb\u7edf\u8bf7\u6c42\u8fdb\u7a0b\u7ec8\u6b62<\/td>\n<td>\u7ec8\u6b62\u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td><strong>SIGHUP<\/strong><\/td>\n<td>\u7ec8\u7aef\u65ad\u5f00\u8fde\u63a5<\/td>\n<td>\u7ec8\u6b62\u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td><strong>SIGQUIT<\/strong><\/td>\n<td>\u7528\u6237\u6309\u4e0b Ctrl+\\ \u9000\u51fa<\/td>\n<td>\u7ec8\u6b62\u8fdb\u7a0b\u5e76\u751f\u6210\u6838\u5fc3\u8f6c\u50a8<\/td>\n<\/tr>\n<tr>\n<td><strong>SIGTSTP<\/strong><\/td>\n<td>\u7528\u6237\u6309\u4e0b Ctrl+Z \u6682\u505c<\/td>\n<td>\u6682\u505c\u8fdb\u7a0b<\/td>\n<\/tr>\n<tr>\n<td><strong>SIGCONT<\/strong><\/td>\n<td>\u7ee7\u7eed\u88ab\u6682\u505c\u7684\u8fdb\u7a0b<\/td>\n<td>\u7ee7\u7eed\u8fdb\u7a0b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>trap \u4f7f\u7528\u793a\u4f8b<\/h3>\n<h4>\u793a\u4f8b 1\uff1a\u6355\u83b7 SIGINT \u6267\u884c\u6e05\u7406<\/h4>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n\ncleanup() {\n    echo &quot;\u811a\u672c\u88ab\u4e2d\u65ad,\u6b63\u5728\u6267\u884c\u6e05\u7406\u64cd\u4f5c...&quot;\n    # \u6e05\u7406\u8d44\u6e90\uff1a\u5173\u95ed\u6587\u4ef6\u3001\u5220\u9664\u4e34\u65f6\u6587\u4ef6\u7b49\n    rm -f \/tmp\/tempfile\n    exit 1\n}\n\n# \u6355\u83b7 SIGINT \u4fe1\u53f7\u5e76\u6267\u884c cleanup \u51fd\u6570\ntrap cleanup SIGINT\n\necho &quot;\u811a\u672c\u6b63\u5728\u8fd0\u884c\uff0c\u6309 Ctrl+C \u6d4b\u8bd5\u4fe1\u53f7\u6355\u83b7...&quot;\nwhile true; do\n    sleep 1\ndone\n<\/code><\/pre>\n<h4>\u793a\u4f8b 2\uff1a\u6355\u83b7\u591a\u4e2a\u4fe1\u53f7<\/h4>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n\nhandle_signals() {\n    case $1 in\n        SIGINT)\n            echo &quot;\u63a5\u6536\u5230\u4e2d\u65ad\u4fe1\u53f7,\u6b63\u5728\u9000\u51fa...&quot;\n            ;;\n        SIGTERM)\n            echo &quot;\u63a5\u6536\u5230\u7ec8\u6b62\u4fe1\u53f7,\u6b63\u5728\u9000\u51fa...&quot;\n            ;;\n        *)\n            echo &quot;\u63a5\u6536\u5230\u672a\u77e5\u4fe1\u53f7: $1&quot;\n            ;;\n    esac\n    # \u6267\u884c\u6e05\u7406\u64cd\u4f5c\n    exit 1\n}\n\n# \u6355\u83b7\u591a\u4e2a\u4fe1\u53f7\ntrap 'handle_signals SIGINT' SIGINT\ntrap 'handle_signals SIGTERM' SIGTERM\n\necho &quot;\u811a\u672c\u6b63\u5728\u8fd0\u884c\uff0c\u7b49\u5f85\u4fe1\u53f7\uff08\u53ef\u53d1\u9001 SIGINT \u6216 SIGTERM \u6d4b\u8bd5\uff09...&quot;\nwhile true; do\n    sleep 1\ndone\n<\/code><\/pre>\n<h4>\u793a\u4f8b 3\uff1a\u5ffd\u7565\u7279\u5b9a\u4fe1\u53f7<\/h4>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n\n# \u5ffd\u7565 CTRL+C \u4fe1\u53f7 (SIGINT)\ntrap '' INT\n\necho &quot;\u5df2\u5ffd\u7565 Ctrl+C \u4e2d\u65ad\u4fe1\u53f7\uff0c\u811a\u672c\u5c06\u65e0\u6cd5\u901a\u8fc7 Ctrl+C \u7ec8\u6b62&quot;\necho &quot;\u6d4b\u8bd5\uff1a\u5c1d\u8bd5\u6309\u4e0b Ctrl+C...&quot;\nsleep 5\necho &quot;\u6d4b\u8bd5\u5b8c\u6210&quot;\n<\/code><\/pre>\n<h4>\u793a\u4f8b 4\uff1a\u6062\u590d\u9ed8\u8ba4\u884c\u4e3a<\/h4>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n\n# \u521d\u59cb\u5ffd\u7565 SIGINT\ntrap '' SIGINT\necho &quot;\u5f53\u524d\u5ffd\u7565 Ctrl+C&quot;\n\n# 5\u79d2\u540e\u6062\u590d\u9ed8\u8ba4\u884c\u4e3a\nsleep 5\ntrap - SIGINT\necho &quot;\u5df2\u6062\u590d Ctrl+C \u7684\u9ed8\u8ba4\u884c\u4e3a&quot;\n\necho &quot;\u73b0\u5728\u53ef\u4ee5\u6309 Ctrl+C \u7ec8\u6b62\u811a\u672c...&quot;\nwhile true; do\n    sleep 1\ndone\n<\/code><\/pre>\n<h2>mktemp\uff08\u4e34\u65f6\u6587\u4ef6\u521b\u5efa\u5de5\u5177\uff09<\/h2>\n<h3>\u57fa\u672c\u8bed\u6cd5<\/h3>\n<pre><code class=\"language-bash\">mktemp [OPTION]... [TEMPLATE]\n<\/code><\/pre>\n<ul>\n<li><code>TEMPLATE<\/code>\uff1a\u5fc5\u987b\u5305\u542b\u81f3\u5c11 6 \u4e2a\u8fde\u7eed <code>X<\/code> (\u5982 <code>tmp.XXXXXX<\/code>)<\/li>\n<\/ul>\n<h3>\u5e38\u7528\u9009\u9879<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u9009\u9879<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-d<\/code><\/td>\n<td>\u521b\u5efa\u4e34\u65f6\u76ee\u5f55<\/td>\n<\/tr>\n<tr>\n<td><code>-u<\/code><\/td>\n<td>\u4ec5\u6253\u5370\u540d\u79f0\uff08\u4e0d\u5b89\u5168\uff09<\/td>\n<\/tr>\n<tr>\n<td><code>-q<\/code><\/td>\n<td>\u5931\u8d25\u65f6\u4e0d\u8f93\u51fa\u8bca\u65ad\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td><code>--suffix=SUFF<\/code><\/td>\n<td>\u6dfb\u52a0\u540e\u7f00<\/td>\n<\/tr>\n<tr>\n<td><code>-p DIR<\/code><\/td>\n<td>\u6307\u5b9a\u7236\u76ee\u5f55<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<pre><code class=\"language-bash\"># \u521b\u5efa\u4e34\u65f6\u6587\u4ef6\nmktemp tmp.XXXXXX\n\n# \u521b\u5efa\u4e34\u65f6\u76ee\u5f55\nmktemp -d tmpdir.XXXXXX\n\n# \u6307\u5b9a\u7236\u76ee\u5f55\nmktemp -p \/custom\/path tmp.XXXXXX\n\n# \u6dfb\u52a0\u540e\u7f00\nmktemp --suffix=.log tmpXXXXXX\n\n# \u9884\u89c8\u6a21\u5f0f\nmktemp -u tmp.XXXXXX\n<\/code><\/pre>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ol>\n<li>\u9ed8\u8ba4\u6743\u9650\uff1a\u4ec5\u6240\u6709\u8005\u53ef\u8bbf\u95ee (600)<\/li>\n<li>\u9700\u624b\u52a8\u5220\u9664\u4e34\u65f6\u6587\u4ef6<\/li>\n<li>\u907f\u514d\u4f7f\u7528 <code>-u<\/code> \u9632\u6b62\u7ade\u6001\u6761\u4ef6<\/li>\n<\/ol>\n<h2>install \u547d\u4ee4<\/h2>\n<h3>\u57fa\u672c\u8bed\u6cd5<\/h3>\n<pre><code class=\"language-bash\">install [OPTION]... SOURCE DEST\ninstall [OPTION]... SOURCE... DIRECTORY\ninstall [OPTION]... -d DIRECTORY...\n<\/code><\/pre>\n<h3>\u5e38\u7528\u9009\u9879<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u9009\u9879<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>-d<\/code><\/td>\n<td>\u521b\u5efa\u76ee\u5f55<\/td>\n<\/tr>\n<tr>\n<td><code>-m MODE<\/code><\/td>\n<td>\u8bbe\u7f6e\u6743\u9650<\/td>\n<\/tr>\n<tr>\n<td><code>-o OWNER<\/code><\/td>\n<td>\u8bbe\u7f6e\u6240\u6709\u8005 (\u9700 root)<\/td>\n<\/tr>\n<tr>\n<td><code>-g GROUP<\/code><\/td>\n<td>\u8bbe\u7f6e\u6240\u5c5e\u7ec4<\/td>\n<\/tr>\n<tr>\n<td><code>-p<\/code><\/td>\n<td>\u4fdd\u7559\u65f6\u95f4\u6233<\/td>\n<\/tr>\n<tr>\n<td><code>-s<\/code><\/td>\n<td>\u5220\u9664\u7b26\u53f7\u8868<\/td>\n<\/tr>\n<tr>\n<td><code>-t DIR<\/code><\/td>\n<td>\u6307\u5b9a\u76ee\u6807\u76ee\u5f55<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<pre><code class=\"language-bash\"># \u590d\u5236\u6587\u4ef6\u5e76\u8bbe\u7f6e\u6743\u9650\ninstall -m 0755 script.sh \/usr\/local\/bin\/\n\n# \u590d\u5236\u6587\u4ef6\u5e76\u8bbe\u7f6e\u6240\u6709\u8005\ninstall -o user -g group file.txt \/target\/\n\n# \u521b\u5efa\u76ee\u5f55\ninstall -d \/path\/to\/newdir\n\n# \u590d\u5236\u591a\u4e2a\u6587\u4ef6\ninstall file1 file2 \/target\/directory\/\n\n# \u4fdd\u7559\u65f6\u95f4\u6233\ninstall -p source dest\n<\/code><\/pre>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ol>\n<li>\u9700\u8981\u8db3\u591f\u6743\u9650\u4fee\u6539\u76ee\u6807\u4f4d\u7f6e<\/li>\n<li>\u9ed8\u8ba4\u8986\u76d6\u5df2\u5b58\u5728\u6587\u4ef6\uff08\u4f7f\u7528 <code>--backup<\/code> \u5907\u4efd\uff09<\/li>\n<li>\u7ec4\u5408\u9009\u9879\u5b9e\u73b0\u590d\u6742\u64cd\u4f5c<\/li>\n<\/ol>\n<h2>\u6570\u7ec4\u64cd\u4f5c<\/h2>\n<h3>\u666e\u901a\u6570\u7ec4<\/h3>\n<pre><code class=\"language-bash\"># \u58f0\u660e\u4e0e\u8d4b\u503c\narr[0]=&quot;A&quot;\narr[1]=&quot;B&quot;\narr=(&quot;A&quot; &quot;B&quot; &quot;C&quot;)\n\n# \u8bbf\u95ee\u5143\u7d20\necho ${arr[1]}  # \u8f93\u51fa &quot;B&quot;\n\n# \u904d\u5386\u5143\u7d20\nfor item in &quot;${arr[@]}&quot;; do\n    echo $item\ndone\n\n# \u6570\u7ec4\u957f\u5ea6\necho ${#arr[@]}  # \u8f93\u51fa 3\n\n# \u5220\u9664\u5143\u7d20\nunset arr[1]  # \u5220\u9664\u7d22\u5f151\u7684\u5143\u7d20\n\n# \u5220\u9664\u6574\u4e2a\u6570\u7ec4\nunset arr\n<\/code><\/pre>\n<h3>\u5173\u8054\u6570\u7ec4<\/h3>\n<pre><code class=\"language-bash\"># \u58f0\u660e\u4e0e\u8d4b\u503c\ndeclare -A assoc_arr\nassoc_arr[&quot;key1&quot;]=&quot;value1&quot;\nassoc_arr[&quot;key2&quot;]=&quot;value2&quot;\n\n# \u8bbf\u95ee\u5143\u7d20\necho ${assoc_arr[&quot;key1&quot;]}  # \u8f93\u51fa &quot;value1&quot;\n\n# \u904d\u5386\u952e\u503c\u5bf9\nfor key in &quot;${!assoc_arr[@]}&quot;; do\n    echo &quot;$key: ${assoc_arr[$key]}&quot;\ndone\n\n# \u68c0\u67e5\u952e\u5b58\u5728\nif [[ -v assoc_arr[&quot;key1&quot;] ]]; then\n    echo &quot;\u952e\u5b58\u5728&quot;\nfi\n\n# \u5220\u9664\u64cd\u4f5c\nunset assoc_arr[&quot;key1&quot;]  # \u5220\u9664\u5355\u4e2a\u5143\u7d20\nunset assoc_arr         # \u5220\u9664\u6574\u4e2a\u6570\u7ec4\n<\/code><\/pre>\n<h2>\u5b57\u7b26\u4e32\u5207\u7247<\/h2>\n<h3>\u5e38\u7528\u65b9\u6cd5<\/h3>\n<pre><code class=\"language-bash\"># ${string:start:length} \u8bed\u6cd5\nstr=&quot;Hello, World!&quot;\necho ${str:7:5}  # \u8f93\u51fa &quot;World&quot;\n\n# ${string:start} \u8bed\u6cd5\nstr=&quot;Hello, World!&quot;\necho ${str:7}    # \u8f93\u51fa &quot;World!&quot;\n\n# ${string: -length} \u8bed\u6cd5\nstr=&quot;Hello, World!&quot;\necho ${str: -6}  # \u8f93\u51fa &quot;World!&quot;\n\n# \u4f7f\u7528 cut \u547d\u4ee4\necho &quot;Hello, World!&quot; | cut -c 8-12  # \u8f93\u51fa &quot;World&quot;\n\n# \u6a21\u5f0f\u5339\u914d\nstr=&quot;Hello123World&quot;\nnum=${str##*[!0-9]*}\nnum=${num%%*[!0-9]*}\necho $num  # \u8f93\u51fa &quot;123&quot;\n<\/code><\/pre>\n<h2>\u53d8\u91cf\u7684\u9ad8\u7ea7\u7528\u6cd5<\/h2>\n<h3>\u53d8\u91cf\u914d\u7f6e\u65b9\u5f0f\u8868<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u914d\u7f6e\u65b9\u5f0f<\/th>\n<th>\u672a\u914d\u7f6e<\/th>\n<th>\u7a7a\u5b57\u7b26\u4e32<\/th>\n<th>\u5df2\u914d\u7f6e\u975e\u7a7a<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>var=${str-expr}<\/code><\/td>\n<td>var=expr<\/td>\n<td>var=\u201c\u201d<\/td>\n<td>var=$str<\/td>\n<\/tr>\n<tr>\n<td><code>var=${str:-expr}<\/code><\/td>\n<td>var=expr<\/td>\n<td>var=expr<\/td>\n<td>var=$str<\/td>\n<\/tr>\n<tr>\n<td><code>var=${str+expr}<\/code><\/td>\n<td>var=\u201c\u201d<\/td>\n<td>var=\u201c\u201d<\/td>\n<td>var=expr<\/td>\n<\/tr>\n<tr>\n<td><code>var=${str:+expr}<\/code><\/td>\n<td>var=\u201c\u201d<\/td>\n<td>var=\u201c\u201d<\/td>\n<td>var=expr<\/td>\n<\/tr>\n<tr>\n<td><code>var=${str=expr}<\/code><\/td>\n<td>str=expr, var=expr<\/td>\n<td>str=\u201c\u201d, var=\u201c\u201d<\/td>\n<td>var=$str<\/td>\n<\/tr>\n<tr>\n<td><code>var=${str:=expr}<\/code><\/td>\n<td>str=expr, var=expr<\/td>\n<td>str=expr, var=expr<\/td>\n<td>var=$str<\/td>\n<\/tr>\n<tr>\n<td><code>var=${str?expr}<\/code><\/td>\n<td>\u62a5\u9519\u9000\u51fa<\/td>\n<td>\u901a\u5e38\u4e0d\u89e6\u53d1<\/td>\n<td>var=$str<\/td>\n<\/tr>\n<tr>\n<td><code>var=${str:?expr}<\/code><\/td>\n<td>\u62a5\u9519\u9000\u51fa<\/td>\n<td>\u62a5\u9519\u9000\u51fa<\/td>\n<td>var=$str<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<blockquote>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a<\/p>\n<ol>\n<li>&quot;\u4fdd\u6301\u672a\u8d4b\u503c\u72b6\u6001&quot;\u53ef\u80fd\u610f\u5473\u7740\u8d4b\u503c\u4e3a\u7a7a\u5b57\u7b26\u4e32<\/li>\n<li><code>var=${str=expr}<\/code>\u5728str\u4e3a\u7a7a\u65f6\u7684\u884c\u4e3a\u4e0d\u5e38\u89c1\uff0c\u5e94\u907f\u514d\u4f7f\u7528<\/li>\n<li>\u5177\u4f53\u884c\u4e3a\u53ef\u80fd\u56e0Shell\u7248\u672c\u800c\u5f02<\/li>\n<\/ol>\n<\/blockquote>\n<h2>\u53d8\u91cf\u7684\u95f4\u63a5\u5f15\u7528<\/h2>\n<h3>\u5f15\u7528\u65b9\u6cd5<\/h3>\n<pre><code class=\"language-bash\"># ${!var} \u8bed\u6cd5 (Bash 4.3+)\nvar_name=&quot;my_var&quot;\nmy_var=&quot;Hello&quot;\necho ${!var_name}  # \u8f93\u51fa &quot;Hello&quot;\n\n# eval \u547d\u4ee4\nvar_name=&quot;my_var&quot;\nmy_var=&quot;Hello&quot;\neval temp_var=\\$$var_name\necho $temp_var  # \u8f93\u51fa &quot;Hello&quot;\n<\/code><\/pre>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ol>\n<li><strong>${!var}<\/strong>\uff1a\u66f4\u5b89\u5168\u7b80\u6d01\uff08\u63a8\u8350\uff09<\/li>\n<li><strong>eval<\/strong>\uff1a\u517c\u5bb9\u6027\u597d\u4f46\u9700\u9632\u6ce8\u5165\u653b\u51fb<\/li>\n<li>\u907f\u514d\u5904\u7406\u7528\u6237\u8f93\u5165\u65f6\u4f7f\u7528\u95f4\u63a5\u5f15\u7528<\/li>\n<\/ol>\n<h2>IFS\uff08Internal Field Separator\uff09<\/h2>\n<h3>\u57fa\u672c\u6982\u5ff5<\/h3>\n<pre><code class=\"language-bash\"># \u9ed8\u8ba4\u503c\uff1a\u7a7a\u683c\u3001\u5236\u8868\u7b26\u3001\u6362\u884c\u7b26\necho &quot;\u9ed8\u8ba4IFS: '$IFS'&quot;\n\n# \u4fee\u6539IFS\nOLDIFS=$IFS\nIFS=','\n\n# \u6062\u590dIFS\nIFS=$OLDIFS\n<\/code><\/pre>\n<h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<pre><code class=\"language-bash\">#!\/bin\/bash\n# \u5904\u7406CSV\u6570\u636e\ndata=&quot;John,30,New York&quot;\n\n# \u4fdd\u5b58\u539f\u59cbIFS\nOLDIFS=$IFS\nIFS=','\n\n# \u8bfb\u53d6\u5b57\u6bb5\nread -r name age city &lt;&lt;&lt; &quot;$data&quot;\necho &quot;Name: $name&quot;\necho &quot;Age: $age&quot;\necho &quot;City: $city&quot;\n\n# \u6062\u590dIFS\nIFS=$OLDIFS\n<\/code><\/pre>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ol>\n<li>\u4fee\u6539\u524d\u4fdd\u5b58\u539f\u59cb\u503c<\/li>\n<li>\u5b50shell\u4fee\u6539\u4e0d\u5f71\u54cd\u7236shell<\/li>\n<li>\u7279\u6b8a\u5b57\u7b26\u9700\u6b63\u786e\u5904\u7406<\/li>\n<li>\u5f71\u54cd\u547d\u4ee4\uff1aread, for\u5faa\u73af, \u53c2\u6570\u6269\u5c55\u7b49<\/li>\n<\/ol>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-109","post","type-post","status-publish","format-standard","hentry","category-linux"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":4,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/posts\/109\/revisions\/119"}],"wp:attachment":[{"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangjianjia.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}