{"id":171,"date":"2021-12-31T14:35:58","date_gmt":"2021-12-31T06:35:58","guid":{"rendered":"https:\/\/program.snlcw.com\/?p=171"},"modified":"2021-12-31T14:35:58","modified_gmt":"2021-12-31T06:35:58","slug":"linux%e5%bc%82%e5%b8%b8%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/program.snlcw.com\/171.html","title":{"rendered":"Linux\u5f02\u5e38\u5904\u7406"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/program.snlcw.com\/171.html\/#1_set_-e_%E5%91%BD%E4%BB%A4\" >1 set -e \u547d\u4ee4<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/program.snlcw.com\/171.html\/#2_%E8%AE%BE%E9%99%B7%E9%98%B1%EF%BC%88trap%EF%BC%89\" >2 \u8bbe\u9677\u9631\uff08trap\uff09<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/program.snlcw.com\/171.html\/#3_grep_%E6%89%BE%E4%B8%8D%E5%88%B0%E4%BC%9A%E6%8A%9B%E5%BC%82%E5%B8%B8\" >3 grep \u627e\u4e0d\u5230\u4f1a\u629b\u5f02\u5e38<\/a><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"1_set_-e_%E5%91%BD%E4%BB%A4\"><\/span><span style=\"font-size: 24px;\">1 set -e \u547d\u4ee4<\/span><span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4f1a\u5728sh\u811a\u672c\u5f00\u5934\u5199\u4e0a<code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">set -e<\/code>\uff0c\u8fd9\u662f\u4e3a\u4e86\u8ba9\u8bed\u53e5\u62a5\u9519\u65f6\uff0c\u53ef\u4ee5\u7acb\u5373\u9000\u51fashell\uff0c\u800c\u4e0d\u662f\u7ee7\u7eed\u6267\u884c\u4e0b\u4e00\u6761\u8bed\u53e5\u3002<\/p>\n<h1><span class=\"ez-toc-section\" id=\"2_%E8%AE%BE%E9%99%B7%E9%98%B1%EF%BC%88trap%EF%BC%89\"><\/span><span style=\"font-size: 24px;\">2 \u8bbe\u9677\u9631\uff08trap\uff09<br \/>\n<\/span><span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u4f7f\u7528 set -e \u65e0\u6cd5\u6355\u83b7\u662f\u54ea\u4e00\u884c\u7684\u547d\u4ee4\u62a5\u9519\u7684\uff0c\u8fd9\u91cc\u6211\u4eec\u6539\u7528trap\u66f4\u597d\uff0c\u5b83\u4e0d\u4ec5\u5177\u6709 set -e\u7684\u529f\u80fd\uff0c\u8fd8\u53ef\u4ee5\u81ea\u5b9a\u4e49\u8f93\u51fa\u6267\u884c\u9519\u8bef\u7684\u547d\u4ee4\u548c\u884c\u53f7\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-theme=\"mootools\">#!\/bin\/bash\r\nf () {\r\n    errcode=$? # save the exit code as the first thing done in the trap function\r\n    echo \"--------------------------------\"\r\n    echo \"error $errorcode\"\r\n    echo \"the command executing at the time of the error was\"\r\n    echo \"$BASH_COMMAND\"\r\n    echo \"on line ${BASH_LINENO[0]}\"\r\n    echo \"--------------------------------\"\r\n    # do some error handling, cleanup, logging, notification\r\n    # $BASH_COMMAND contains the command that was being executed at the time of the trap\r\n    # ${BASH_LINENO[0]} contains the line number in the script of that command\r\n    # exit the script or return to try again, etc.\r\n    exit $errcode  # or use some other value or do return instead\r\n}\r\ntrap f ERR\r\n\r\nls | grep abcd  #\u8fd9\u91cc\u67e5\u8be2\u4e0d\u5230 abcd \u5c31\u76f4\u63a5\u9000\u51fa\r\n#false #\u6216\u8005\u76f4\u63a5\u8f93\u5165false\uff0c\u4e5f\u4f1a\u89e6\u53d1trap\r\n<\/pre>\n<h1><span class=\"ez-toc-section\" id=\"3_grep_%E6%89%BE%E4%B8%8D%E5%88%B0%E4%BC%9A%E6%8A%9B%E5%BC%82%E5%B8%B8\"><\/span><span style=\"font-size: 24px;\">3 grep \u627e\u4e0d\u5230\u4f1a\u629b\u5f02\u5e38<\/span><span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u4e0a\u9762\u811a\u672c\u5df2\u7ecf\u63d0\u5230\uff0c\u5f53\u6267\u884c\u00a0\u201cls | grep abcd\u201d\u00a0 \u65f6\uff0c\u5982\u679c\u627e\u4e0d\u5230\u5b57\u7b26\u4e32\u201cabcd\u201d\uff0c\u5c31\u4f1a\u62a5\u9519\u3002\u5982\u679c\u4f60\u8bbe\u7f6e\u4e86 \u201cset -e\u201d\u6216\u201ctrap\u201d\uff0c\u5c31\u4f1a\u76f4\u63a5\u9000\u51fa\uff0c\u4e0d\u518d\u5411\u4e0b\u6267\u884c\u547d\u4ee4\u3002<\/p>\n<p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u5e76\u4e0d\u60f3\u56e0\u4e3a grep\u627e\u4e0d\u5230\u5b57\u7b26\u4e32\u800c\u76f4\u63a5\u9000\u51fa\uff0c\u8fd9\u65f6\u53ef\u4ee5\u518dgrep\u540e\u9762\u6dfb\u52a0\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">| { grep -v grep || true; }<\/code>\u6765\u89e3\u51b3\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-theme=\"mootools\">SHA_FILE=`cat image\/falsolr.${FAL_VERSION}.sha | awk '{print substr($1,8,12)}'`\r\nIMAGE_GREP=`docker image ls | grep ${SHA_FILE} | { grep -v grep || true; }`\r\nif [ -z \"$IMAGE_GREP\" ]\r\nthen\r\n    docker load -i ${SOLR_IMAGE}\r\nfi\r\n<!--\/codes_iframe--><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1 set -e \u547d\u4ee4 \u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4f1a\u5728sh\u811a\u672c\u5f00\u5934\u5199\u4e0aset -e\uff0c\u8fd9\u662f\u4e3a\u4e86\u8ba9\u8bed\u53e5\u62a5\u9519\u65f6\uff0c\u53ef\u4ee5\u7acb\u5373\u9000\u51fas\u2026 <span class=\"read-more\"><a href=\"https:\/\/program.snlcw.com\/171.html\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":0,"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"wp:attachment":[{"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/program.snlcw.com\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}