{"id":2562,"date":"2015-12-12T10:45:18","date_gmt":"2015-12-12T02:45:18","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2562"},"modified":"2015-12-12T10:45:18","modified_gmt":"2015-12-12T02:45:18","slug":"shell%e8%84%9a%e6%9c%ac%e8%b0%83%e8%af%95%e6%8a%80%e6%9c%af","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2562.html","title":{"rendered":"Shell\u811a\u672c\u8c03\u8bd5\u6280\u672f"},"content":{"rendered":"<p>=Start=<\/p>\n<p>\u524d\u6bb5\u65f6\u95f4\u5199Shell\u811a\u672c\u6bd4\u8f83\u591a\uff0c\u5bf9shell\u811a\u672c\u7684\u8c03\u8bd5\u6280\u672f\/\u6280\u5de7\u6709\u4e00\u5b9a\u9700\u6c42\u3002\u7136\u540e\u901a\u8fc7\u4e00\u4e9b\u603b\u7ed3\u548c\u9488\u5bf9\u6027\u7684\u641c\u7d22\uff0c\u5c31\u6709\u4e86\u8fd9\u7bc7\u6587\u7ae0\u3002<\/p>\n<h5 id=\"Shell\u811a\u672c\u8c03\u8bd5\u6280\u672f-\u5185\u5bb9-(what&amp;how)\">\u5185\u5bb9<\/h5>\n<p>\u5bf9&#8221;-x&#8221;\u9009\u9879\u7684\u589e\u5f3a<\/p>\n<p>&#8220;-x&#8221;\u6267\u884c\u9009\u9879\u662f\u76ee\u524d\u6700\u5e38\u7528\u7684\u8ddf\u8e2a\u548c\u8c03\u8bd5shell\u811a\u672c\u7684\u624b\u6bb5\uff0c\u4f46\u5176\u8f93\u51fa\u7684\u8c03\u8bd5\u4fe1\u606f\u4ec5\u9650\u4e8e\u8fdb\u884c\u53d8\u91cf\u66ff\u6362\u4e4b\u540e\u7684\u6bcf\u4e00\u6761\u5b9e\u9645\u6267\u884c\u7684\u547d\u4ee4\u4ee5\u53ca\u884c\u9996\u7684\u4e00\u4e2a&#8221;+&#8221;\u53f7\u63d0\u793a\u7b26\uff0c\u5c45\u7136\u8fde\u884c\u53f7\u8fd9\u6837\u7684\u91cd\u8981\u4fe1\u606f\u90fd\u6ca1\u6709\uff0c\u5bf9\u4e8e\u590d\u6742\u7684shell\u811a\u672c\u7684\u8c03\u8bd5\u6765\u8bf4\uff0c\u8fd8\u662f\u975e\u5e38\u7684\u4e0d\u65b9\u4fbf\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u5de7\u5999\u5730\u5229\u7528shell\u5185\u7f6e\u7684\u4e00\u4e9b\u73af\u5883\u53d8\u91cf\u6765\u589e\u5f3a&#8221;-x&#8221;\u9009\u9879\u7684\u8f93\u51fa\u4fe1\u606f\uff0c\u4e0b\u9762\u5148\u4ecb\u7ecd\u51e0\u4e2ashell\u5185\u7f6e\u7684\u73af\u5883\u53d8\u91cf\uff1a<\/p>\n<h6>$LINENO<\/h6>\n<p>\u4ee3\u8868<span style=\"color: #ff0000;\"><strong>shell\u811a\u672c\u7684\u5f53\u524d\u884c\u53f7<\/strong><\/span>\uff0c\u7c7b\u4f3c\u4e8eC\u8bed\u8a00\u4e2d\u7684\u5185\u7f6e\u5b8f__LINE__<\/p>\n<h6>$FUNCNAME<\/h6>\n<p>\u51fd\u6570\u7684\u540d\u5b57\uff0c\u7c7b\u4f3c\u4e8eC\u8bed\u8a00\u4e2d\u7684\u5185\u7f6e\u5b8f__func__,\u4f46\u5b8f__func__\u53ea\u80fd\u4ee3\u8868\u5f53\u524d\u6240\u5728\u7684\u51fd\u6570\u540d\uff0c\u800c<span style=\"color: #ff0000;\"><strong>$FUNCNAME\u7684\u529f\u80fd\u66f4\u5f3a\u5927\uff0c\u5b83\u662f\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u6574\u4e2a\u8c03\u7528\u94fe\u4e0a\u6240\u6709\u7684\u51fd\u6570\u7684\u540d\u5b57<\/strong><\/span>\uff0c\u6545\u53d8\u91cf${FUNCNAME[0]}\u4ee3\u8868shell\u811a\u672c\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u51fd\u6570\u7684\u540d\u5b57\uff0c\u800c\u53d8\u91cf${FUNCNAME[1]}\u5219\u4ee3\u8868\u8c03\u7528\u51fd\u6570${FUNCNAME[0]}\u7684\u51fd\u6570\u7684\u540d\u5b57\uff0c\u4f59\u8005\u53ef\u4ee5\u4f9d\u6b64\u7c7b\u63a8\u3002<\/p>\n<h6>$PS4<\/h6>\n<p>\u4e3b\u63d0\u793a\u7b26\u53d8\u91cf$PS1\u548c\u7b2c\u4e8c\u7ea7\u63d0\u793a\u7b26\u53d8\u91cf$PS2\u6bd4\u8f83\u5e38\u89c1\uff0c\u4f46\u5f88\u5c11\u6709\u4eba\u6ce8\u610f\u5230\u7b2c\u56db\u7ea7\u63d0\u793a\u7b26\u53d8\u91cf$PS4\u7684\u4f5c\u7528\u3002\u6211\u4eec\u77e5\u9053\u4f7f\u7528\u201c-x\u201d\u6267\u884c\u9009\u9879\u5c06\u4f1a\u663e\u793ashell\u811a\u672c\u4e2d\u6bcf\u4e00\u6761\u5b9e\u9645\u6267\u884c\u8fc7\u7684\u547d\u4ee4\uff0c\u800c<span style=\"color: #ff0000;\"><strong>$PS4\u7684\u503c\u5c06\u88ab\u663e\u793a\u5728\u201c-x\u201d\u9009\u9879\u8f93\u51fa\u7684\u6bcf\u4e00\u6761\u547d\u4ee4\u7684\u524d\u9762<\/strong><\/span>\u3002\u5728Bash Shell\u4e2d\uff0c\u7f3a\u7701\u7684$PS4\u7684\u503c\u662f&#8221;+&#8221;\u53f7\u3002(\u73b0\u5728\u77e5\u9053\u4e3a\u4ec0\u4e48\u4f7f\u7528&#8221;-x&#8221;\u9009\u9879\u65f6\uff0c\u8f93\u51fa\u7684\u547d\u4ee4\u524d\u9762\u6709\u4e00\u4e2a&#8221;+&#8221;\u53f7\u4e86\u5427\uff1f)\u3002<\/p>\n<p>\u5229\u7528$PS4\u8fd9\u4e00\u7279\u6027\uff0c\u901a\u8fc7\u4f7f\u7528\u4e00\u4e9b\u5185\u7f6e\u53d8\u91cf\u6765\u91cd\u5b9a\u4e49$PS4\u7684\u503c\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u589e\u5f3a&#8221;-x&#8221;\u9009\u9879\u7684\u8f93\u51fa\u4fe1\u606f\u3002\u4f8b\u5982\u5148\u6267\u884cexport PS4=&#8217;+{$LINENO:${FUNCNAME[0]}} &#8216;, \u7136\u540e\u518d\u4f7f\u7528\u201c-x\u201d\u9009\u9879\u6765\u6267\u884c\u811a\u672c\uff0c\u5c31\u80fd\u5728\u6bcf\u4e00\u6761\u5b9e\u9645\u6267\u884c\u7684\u547d\u4ee4\u524d\u9762\u663e\u793a\u5176\u884c\u53f7\u4ee5\u53ca\u6240\u5c5e\u7684\u51fd\u6570\u540d\u3002<\/p>\n<pre class=\"lang:default decode:true\">set -x\nexport PS4='+{${FUNCNAME[0]}@$LINENO}'\nexport PS4='+${BASH_SOURCE}:${LINENO}:${FUNCNAME[0]}: '\n\n$ man bash\nPS1    The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string.  The default value is ``\\s-\\v\\$ ''.\nPS2    The value of this parameter is expanded as with PS1 and used as the secondary prompt string.  The default is ``&gt; ''.\nPS3    The value of this parameter is used as the prompt for the select command (see SHELL GRAMMAR above).\nPS4    The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is ``+ ''.<\/pre>\n<h6 id=\"Shell\u811a\u672c\u8c03\u8bd5\u6280\u672f-\u53c2\u8003\u94fe\u63a5\">\u53c2\u8003\u94fe\u63a5<\/h6>\n<ul>\n<li><a href=\"https:\/\/www.ibm.com\/developerworks\/cn\/linux\/l-cn-shell-debug\/\" target=\"_blank\">https:\/\/www.ibm.com\/developerworks\/cn\/linux\/l-cn-shell-debug\/<\/a><\/li>\n<li><a href=\"http:\/\/www.thegeekstuff.com\/2008\/09\/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command\/\" target=\"_blank\">http:\/\/www.thegeekstuff.com\/2008\/09\/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command\/<\/a><\/li>\n<li><a href=\"http:\/\/coolshell.cn\/articles\/1379.html\" target=\"_blank\">http:\/\/coolshell.cn\/articles\/1379.html<\/a><\/li>\n<li><a href=\"http:\/\/blog.deepin.org\/2012\/12\/ps1-ps2-ps3-ps4-variables-explained\/\" target=\"_blank\">http:\/\/blog.deepin.org\/2012\/12\/ps1-ps2-ps3-ps4-variables-explained\/<\/a><\/li>\n<li><a href=\"http:\/\/dongweiming.github.io\/blog\/archives\/ps1ps2ps3ps4%E5%92%8Cprompt_command\/\" target=\"_blank\">http:\/\/dongweiming.github.io\/blog\/archives\/ps1ps2ps3ps4%E5%92%8Cprompt_command\/<\/a><\/li>\n<\/ul>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u524d\u6bb5\u65f6\u95f4\u5199Shell\u811a\u672c\u6bd4\u8f83\u591a\uff0c\u5bf9shell\u811a\u672c\u7684\u8c03\u8bd5\u6280\u672f\/\u6280\u5de7\u6709\u4e00\u5b9a\u9700\u6c42\u3002\u7136\u540e\u901a\u8fc7\u4e00\u4e9b\u603b\u7ed3\u548c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,7],"tags":[575,65,19],"class_list":["post-2562","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-programing","tag-debug","tag-shell","tag-tips"],"views":5927,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2562"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2562\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}