{"id":1173,"date":"2022-02-11T09:34:31","date_gmt":"2022-02-11T09:34:31","guid":{"rendered":"http:\/\/www.liutianfeng.com\/?p=1173"},"modified":"2022-02-11T09:34:31","modified_gmt":"2022-02-11T09:34:31","slug":"shell%e5%ae%9e%e7%8e%b0%e7%b1%bb%e4%bc%bcgoto%e7%9a%84%e5%8a%9f%e8%83%bd-%e8%b7%b3%e8%bd%ac%e5%88%b0%e5%90%8e%e9%9d%a2%e7%9a%84%e6%9f%90%e6%ae%b5%e4%bb%a3%e7%a0%81%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/www.liutianfeng.com\/?p=1173","title":{"rendered":"shell\u5b9e\u73b0\u7c7b\u4f3cgoto\u7684\u529f\u80fd &#8211; \u8df3\u8f6c\u5230\u540e\u9762\u7684\u67d0\u6bb5\u4ee3\u7801\u4e2d"},"content":{"rendered":"<h2>1.\u00a0goto\u51fd\u6570<\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"\"># 1. go|check, 2. \u8df3\u8f6c\u7684FUNCNAME[go\u65f6]|check\u65f6\u5165\u53c2\u4e3agoto\u6267\u884c\u65f6\u6240\u5728\u7684FUNCNAME\r\nfunction goto() {\r\n    case ${1} in\r\n        go)\r\n            FUNC_GOTO=${2}\r\n            ;;\r\n        check)\r\n            [ -z ${FUNC_GOTO} ] &amp;&amp; return\r\n            if [ \"x${2}\" != \"x${FUNC_GOTO}\" ]; then\r\n                return 232\r\n            else\r\n                unset FUNC_GOTO\r\n            fi\r\n            ;;\r\n        *)\r\n            ;;\r\n    esac\r\n}<\/code><\/pre>\n<h2>2.\u00a0\u8df3\u8f6c<\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"\">goto go FUNC_NAME_TO_GO<\/code><\/pre>\n<p>\u6ce8\u610f\uff0c\u8fd9\u91cc\u7684goto\uff0c\u662f\u901a\u8fc7function\u4e2d\u5185\u5efa\u7684FUNCNAME\u53d8\u91cf\u6765\u5b9e\u73b0\u6821\u9a8c\u7684\uff0c\u56e0\u6b64\uff0c\u8df3\u8f6c\u5230\u7684\u90e8\u5206\uff0c\u9700\u8981\u5c01\u88c5\u6210function\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\"># cat skelchina.sh \r\n#!\/bin\/bash\r\nfunction skelChina () {\r\n    echo \"Function Name: ${FUNCNAME}\"\r\n}\r\n\r\nskelChina\r\n\r\n# sh skelchina.sh\r\nFunction Name: skelChina<\/code><\/pre>\n<h2>3.\u00a0\u6821\u9a8c<\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"\">goto check ${FUNCNAME} || return 232  # check\u8fd4\u56de\u4e0d\u4e3a0\u65f6,\u00a0\u76f4\u63a5return<\/code><\/pre>\n<h2>4.\u00a0\u793a\u4f8b<\/h2>\n<pre class=\"pure-highlightjs\"><code class=\"\"># cat skelchina.sh\r\n#!\/bin\/bash\r\n\r\nfunction goto() {\r\n    case ${1} in\r\n        go)\r\n            FUNC_GOTO=${2}\r\n            ;;\r\n        check)\r\n            [ -z ${FUNC_GOTO} ] &amp;&amp; return\r\n            if [ \"x${2}\" != \"x${FUNC_GOTO}\" ]; then\r\n                return 232\r\n            else\r\n                unset FUNC_GOTO\r\n            fi\r\n            ;;\r\n        *)\r\n            ;;\r\n    esac\r\n}\r\n\r\nfunction liemer () {\r\n    goto check ${FUNCNAME} || return 232\r\n    echo Liemer\r\n}\r\n\r\nfunction lius () {\r\n    goto check ${FUNCNAME} || return 232\r\n    echo Lius\r\n}\r\n\r\ngoto go lius\r\n\r\n# \u8c03\u7528\u4e24\u4e2a\r\nliemer\r\nlius\r\n# sh skelchina.sh   # liemer\u51fd\u6570\u6821\u9a8c\u6ca1\u8fc7, \u4e0d\u6267\u884c\r\nLius<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.liutianfeng.com\">liutianfeng.com<\/a> &raquo; <a href=\"https:\/\/www.liutianfeng.com\/?p=1173\">shell\u5b9e\u73b0\u7c7b\u4f3cgoto\u7684\u529f\u80fd &#8211; \u8df3\u8f6c\u5230\u540e\u9762\u7684\u67d0\u6bb5\u4ee3\u7801\u4e2d<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>1.\u00a0goto\u51fd\u6570 # 1. go|check, 2. \u8df3\u8f6c\u7684FUNCNAME[go\u65f6]|check\u65f6\u5165\u53c2\u4e3ag [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1173"}],"collection":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1173"}],"version-history":[{"count":1,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1173\/revisions"}],"predecessor-version":[{"id":1174,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1173\/revisions\/1174"}],"wp:attachment":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}