{"id":2512,"date":"2015-11-07T15:43:33","date_gmt":"2015-11-07T07:43:33","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2512"},"modified":"2015-11-07T15:43:33","modified_gmt":"2015-11-07T07:43:33","slug":"bash%e4%b8%ad%e5%86%92%e5%8f%b7%e7%9a%84%e4%bd%9c%e7%94%a8%e5%92%8c%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2512.html","title":{"rendered":"Bash\u4e2d\u5192\u53f7(:)\u7684\u4f5c\u7528\u548c\u7528\u6cd5"},"content":{"rendered":"<p>=Start=<\/p>\n<h6>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h6>\n<ul>\n<li>linux shell colon<\/li>\n<li>linux Bash \u5192\u53f7<\/li>\n<\/ul>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/3224878\/what-is-the-purpose-of-the-colon-gnu-bash-builtin\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/3224878\/what-is-the-purpose-of-the-colon-gnu-bash-builtin<\/a> #\u5168\u9762<\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fstackoverflow.com%2Fquestions%2F10797835%2Fwhile-vs-while-true\"><a href=\"http:\/\/stackoverflow.com\/questions\/10797835\/while-vs-while-true\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/10797835\/while-vs-while-true<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Funix.stackexchange.com%2Fquestions%2F31673%2Fwhat-purpose-does-the-colon-builtin-serve\"><a href=\"http:\/\/unix.stackexchange.com\/questions\/31673\/what-purpose-does-the-colon-builtin-serve\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/31673\/what-purpose-does-the-colon-builtin-serve<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fsuperuser.com%2Fquestions%2F423980%2Fcolon-command-for-bash\"><a href=\"http:\/\/superuser.com\/questions\/423980\/colon-command-for-bash\" target=\"_blank\">http:\/\/superuser.com\/questions\/423980\/colon-command-for-bash<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Faskubuntu.com%2Fquestions%2F549608%2Fwhat-is-the-point-of-the-bash-null-operator-colon\"><a href=\"http:\/\/askubuntu.com\/questions\/549608\/what-is-the-point-of-the-bash-null-operator-colon\" target=\"_blank\">http:\/\/askubuntu.com\/questions\/549608\/what-is-the-point-of-the-bash-null-operator-colon<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Faplawrence.com%2FBasics%2Fleading-colon.html\"><a href=\"http:\/\/aplawrence.com\/Basics\/leading-colon.html\" target=\"_blank\">http:\/\/aplawrence.com\/Basics\/leading-colon.html<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fwww.cnblogs.com%2Fchengmo%2Farchive%2F2010%2F10%2F02%2F1841355.html\"><a href=\"http:\/\/www.cnblogs.com\/chengmo\/archive\/2010\/10\/02\/1841355.html\" target=\"_blank\">http:\/\/www.cnblogs.com\/chengmo\/archive\/2010\/10\/02\/1841355.html<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fblog.chinaunix.net%2Fuid-1835840-id-2831521.html\"><a href=\"http:\/\/blog.chinaunix.net\/uid-1835840-id-2831521.html\" target=\"_blank\">http:\/\/blog.chinaunix.net\/uid-1835840-id-2831521.html<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fgithub.tiankonguse.com%2Fblog%2F2015%2F04%2F19%2Fbash-colon%2F\"><a href=\"http:\/\/github.tiankonguse.com\/blog\/2015\/04\/19\/bash-colon\/\" target=\"_blank\">http:\/\/github.tiankonguse.com\/blog\/2015\/04\/19\/bash-colon\/<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fblog.useasp.net%2Farchive%2F2014%2F06%2F02%2Fsummary-of-the-special-characters-in-shell-on-linux.aspx\"><a href=\"http:\/\/blog.useasp.net\/archive\/2014\/06\/02\/summary-of-the-special-characters-in-shell-on-linux.aspx\" target=\"_blank\">http:\/\/blog.useasp.net\/archive\/2014\/06\/02\/summary-of-the-special-characters-in-shell-on-linux.aspx<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fwww.jb51.net%2Farticle%2F51342.htm\"><a href=\"http:\/\/www.jb51.net\/article\/51342.htm\" target=\"_blank\">http:\/\/www.jb51.net\/article\/51342.htm<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Ffanwen.freexs.cn%2Fjiaoben%2F192343.html\"><a href=\"http:\/\/fanwen.freexs.cn\/jiaoben\/192343.html\" target=\"_blank\">http:\/\/fanwen.freexs.cn\/jiaoben\/192343.html<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Ftldp.org%2FLDP%2Fabs%2Fhtml%2Fspecial-chars.html\"><a href=\"http:\/\/tldp.org\/LDP\/abs\/html\/special-chars.html\" target=\"_blank\">http:\/\/tldp.org\/LDP\/abs\/html\/special-chars.html<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Flinux.about.com%2Flibrary%2Fbl%2Fopen%2Fnewbie%2Fblnewbie3.4.8.htm\"><a href=\"http:\/\/linux.about.com\/library\/bl\/open\/newbie\/blnewbie3.4.8.htm\" target=\"_blank\">http:\/\/linux.about.com\/library\/bl\/open\/newbie\/blnewbie3.4.8.htm<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fcodingstandards.iteye.com%2Fblog%2F1160298\"><a href=\"http:\/\/codingstandards.iteye.com\/blog\/1160298\" target=\"_blank\">http:\/\/codingstandards.iteye.com\/blog\/1160298<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fcodingstandards.iteye.com%2Fblog%2F786653\"><a href=\"http:\/\/codingstandards.iteye.com\/blog\/786653\" target=\"_blank\">http:\/\/codingstandards.iteye.com\/blog\/786653<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fwww.gnu.org%2Fsoftware%2Fbash%2Fmanual%2Fbashref.html%23Special-Parameters\"><a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/bashref.html#Special-Parameters\" target=\"_blank\">http:\/\/www.gnu.org\/software\/bash\/manual\/bashref.html#Special-Parameters<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fwww.tutorialspoint.com%2Funix%2Funix-special-variables.htm\"><a href=\"http:\/\/www.tutorialspoint.com\/unix\/unix-special-variables.htm\" target=\"_blank\">http:\/\/www.tutorialspoint.com\/unix\/unix-special-variables.htm<\/a><\/li>\n<li data-wpview-marker=\"http%3A%2F%2Fwww.gnu.org%2Fsoftware%2Fbash%2Fmanual%2Fhtml_node%2FBourne-Shell-Builtins.html\"><a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/html_node\/Bourne-Shell-Builtins.html\" target=\"_blank\">http:\/\/www.gnu.org\/software\/bash\/manual\/html_node\/Bourne-Shell-Builtins.html<\/a><\/li>\n<\/ul>\n<h6>\u53c2\u8003\u89e3\u7b54\uff1a<\/h6>\n<pre class=\"lang:default decode:true\">$ man :\n$ man builtin\n\n: [arguments]\n\tNo effect; the command does nothing beyond expanding arguments and performing any specified redirections.  A zero exit code is returned.<\/pre>\n<p>\u4e0a\u9762\u7684man\u624b\u518c\u8bf4 \u5192\u53f7(:) \u662f&#8221;No effect&#8221;\u7684\uff0c\u4f46\u5982\u679c\u771f\u7684\u662f\u4e00\u70b9\u4f5c\u7528\u90fd\u6ca1\u6709\u7684\u8bdd\uff0c\u4e3a\u4ec0\u4e48\u4f1a\u6709\u5b58\u5728\u7684\u5fc5\u8981\u5462\uff1f<\/p>\n<p>\u56e0\u4e3a\u5728\u5386\u53f2\u4e0a\uff0cBourne shell\u6ca1\u6709\u5185\u5efa\u7684 true\/false \u547d\u4ee4\uff0c\u56e0\u6b64\u7528 \u5192\u53f7(:) \u4ee3\u8868 true \uff0c\u7528 &#8220;let 0&#8221; \u8fd9\u6837\u7684\u4ee3\u8868 false \u3002\u5e76\u4e14\uff0c\u5728\u7531 Bourne shell \u884d\u751f\u51fa\u6765\u7684shell\u4e2d \u5192\u53f7(:) \u8981\u6bd4 true \u7a0d\u5fae\u5feb\u90a3\u4e48\u4e00\u70b9\u3002<\/p>\n<p>\u800c\u4e14\uff0c\u5192\u53f7(:)\u5e76\u4e0d\u662f\u4e00\u70b9\u4f5c\u7528\u90fd\u6ca1\u6709\u7684\uff0c\u4e0b\u9762\u5c31\u662f\u5192\u53f7(:)\u5e38\u89c1\u7684\u7528\u6cd5\uff1a<\/p>\n<h6>1.\u53d8\u91cf\u9ed8\u8ba4\u503c(\u53c2\u6570\u6269\u5c55)<\/h6>\n<p>\u5f53\u53d8\u91cfVAR\u6ca1\u6709\u58f0\u660e\u6216\u8005\u4e3aNULL\u65f6\uff0c\u5c06VAR\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u503cDEFAULT<\/p>\n<pre class=\"lang:default decode:true\">${VAR:=DEFAULT}<\/pre>\n<p><span style=\"font-weight: bold;\">2.\u7a7a\u8bed\u53e5(\u5360\u4f4d\u7b26)<\/span><\/p>\n<pre class=\"lang:default decode:true\">if [ -f \"\/etc\/passwd\" ]; then\n    echo \"hi\"\nelse\n    :\nfi<\/pre>\n<h6>3.\u6e05\u7a7a\u6587\u4ef6<\/h6>\n<pre class=\"lang:default decode:true\">:&gt; test<\/pre>\n<h6>4.\u6ce8\u91ca(#\u540e\u7684\u6ce8\u91ca\u5185\u5bb9\u4e0d\u4f1a\u88ab\u68c0\u67e5\uff0c\u4f46:\u540e\u7684\u6ce8\u91ca\u5185\u5bb9\u4f1a\u88ab\u68c0\u67e5\uff0c\u5982\u679c\u6709\u8bed\u53e5\u5982\u679c\u51fa\u73b0\u8bed\u6cd5\u9519\u8bef\uff0c\u5219\u4f1a\u62a5\u9519)<\/h6>\n<p>\u683c\u5f0f\uff1a: your comment here<br \/>\n\u683c\u5f0f\uff1a# your comment here<br \/>\n\u5199<span style=\"color: #ff0000;\"><strong>\u5355\u884c\u6ce8\u91ca<\/strong><\/span>\u3002<\/p>\n<p>\u683c\u5f0f\uff1a: &#8216;comment line1<br \/>\ncomment line2<br \/>\nmore comments&#8217;<br \/>\n\u5199<strong><span style=\"color: #ff0000;\">\u591a\u884c\u6ce8\u91ca<\/span><\/strong>\u3002<\/p>\n<h6>5.\u4f5c\u4e3a\u51fd\u6570\u540d<\/h6>\n<p>\u4e0d\u8fc7\u8fd9\u4e2a\u4f1a\u5c06\u5192\u53f7\u7684\u672c\u6765\u610f\u4e49\u8f6c\u53d8\uff08\u5982\u679c\u4f60\u4e0d\u5c0f\u5fc3\u5c06\u5192\u53f7\u4f5c\u4e3a\u51fd\u6570\u540d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528unset -f : \u6765\u53d6\u6d88function\u7684\u5b9a\u4e49\uff09<\/p>\n<p>=EOF=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u641c\u7d22\u5173\u952e\u5b57\uff1a linux shell colon linux Bash \u5192\u53f7 \u53c2\u8003\u94fe\u63a5\uff1a ht [&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":[83,65,19],"class_list":["post-2512","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-programing","tag-bash","tag-shell","tag-tips"],"views":5013,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2512","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=2512"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2512\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}