{"id":1213,"date":"2019-04-29T09:52:08","date_gmt":"2019-04-29T01:52:08","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=1213"},"modified":"2019-04-29T09:52:08","modified_gmt":"2019-04-29T01:52:08","slug":"bash%e5%92%8cbourne_shell%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=1213","title":{"rendered":"bash\u548cBourne_shell\u7684\u533a\u522b"},"content":{"rendered":"<p>Linux \u4e2d\u7684 shell \u6709\u5f88\u591a\u7c7b\u578b\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u51e0\u79cd\u662f: Bourne shell (sh)\u3001C shell (csh) \u548c Korn shell (ksh), \u5404\u6709\u4f18\u7f3a\u70b9\u3002Bourne shell \u662f UNIX \u6700\u521d\u4f7f\u7528\u7684 shell\uff0c\u5e76\u4e14\u5728\u6bcf\u79cd UNIX \u4e0a\u90fd\u53ef\u4ee5\u4f7f\u7528, \u5728 shell \u7f16\u7a0b\u65b9\u9762\u76f8\u5f53\u4f18\u79c0\uff0c\u4f46\u5728\u5904\u7406\u4e0e\u7528\u6237\u7684\u4ea4\u4e92\u65b9\u9762\u505a\u5f97\u4e0d\u5982\u5176\u4ed6\u51e0\u79cdshell\u3002Linux \u64cd\u4f5c\u7cfb\u7edf\u7f3a\u7701\u7684 shell \u662fBourne Again shell\uff0c\u5b83\u662f Bourne shell \u7684\u6269\u5c55\uff0c\u7b80\u79f0 Bash\uff0c\u4e0e Bourne shell \u5b8c\u5168\u5411\u540e\u517c\u5bb9\uff0c\u5e76\u4e14\u5728Bourne shell \u7684\u57fa\u7840\u4e0a\u589e\u52a0\u3001\u589e\u5f3a\u4e86\u5f88\u591a\u7279\u6027\u3002Bash\u653e\u5728\/bin\/bash\u4e2d\uff0c\u5b83\u6709\u8bb8\u591a\u7279\u8272\uff0c\u53ef\u4ee5\u63d0\u4f9b\u5982\u547d\u4ee4\u8865\u5168\u3001\u547d\u4ee4\u7f16\u8f91\u548c\u547d\u4ee4\u5386\u53f2\u8868\u7b49\u529f\u80fd\uff0c\u5b83\u8fd8\u5305\u542b\u4e86\u5f88\u591a C shell \u548c Korn shell \u4e2d\u7684\u4f18\u70b9\uff0c\u6709\u7075\u6d3b\u548c\u5f3a\u5927\u7684\u7f16\u7a0b\u63a5\u53e3\uff0c\u540c\u65f6\u53c8\u6709\u5f88\u53cb\u597d\u7684\u7528\u6237\u754c\u9762\u3002<\/p>\n<div>\n<div><\/div>\n<div>\u00a0 \u00a0 GNU\/Linux \u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684 \/bin\/sh \u672c\u662f bash (Bourne-Again Shell) \u7684\u7b26\u53f7\u94fe\u63a5\uff0c\u4f46\u9274\u4e8e bash \u8fc7\u4e8e\u590d\u6742\uff0c\u6709\u4eba\u628a ash \u4ece NetBSD \u79fb\u690d\u5230 Linux \u5e76\u66f4\u540d\u4e3a dash (Debian Almquist Shell)\uff0c\u5e76\u5efa\u8bae\u5c06 \/bin\/sh \u6307\u5411\u5b83\uff0c\u4ee5\u83b7\u5f97\u66f4\u5feb\u7684\u811a\u672c\u6267\u884c\u901f\u5ea6\u3002Dash Shell \u6bd4 Bash Shell \u5c0f\u7684\u591a\uff0c\u7b26\u5408POSIX\u6807\u51c6\u3002<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0 Ubuntu\u7ee7\u627f\u4e86Debian\uff0c\u6240\u4ee5\u4eceUbuntu 6.10\u5f00\u59cb\u9ed8\u8ba4\u662fDash Shell\u3002<\/div>\n<div>\n<div id=\"codeText\" class=\"codeText\">\n<ol class=\"dp-css\" start=\"1\">\n<li>\u00a0luotaijia@ubuntu:~$\u00a0ls\u00a0-l\u00a0\/bin\/sh\u00a0\/bin\/bash<\/li>\n<li>\u00a0-rwxr-xr-x 1 root root 801808 2010-08-11 03:58\u00a0\/bin\/bash<\/li>\n<li>\u00a0lrwxrwxrwx 1 root root 4 2012-11-28 08:06\u00a0\/bin\/sh\u00a0-&gt;\u00a0dash<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<div><\/div>\n<div>\u00a0 \u00a0\u00a0\u5e94\u8be5\u8bf4, \/bin\/sh \u4e0e \/bin\/bash \u867d\u7136\u5927\u4f53\u4e0a\u6ca1\u4ec0\u4e48\u533a\u522b, \u4f46\u4ecd\u5b58\u5728\u4e0d\u540c\u7684\u6807\u51c6. \u6807\u8bb0\u4e3a \u201c#!\/bin\/sh\u201d \u7684\u811a\u672c\u4e0d\u5e94\u4f7f\u7528\u4efb\u4f55 POSIX \u6ca1\u6709\u89c4\u5b9a\u7684\u7279\u6027 (\u5982 let \u7b49\u547d\u4ee4, \u4f46 \u201c#!\/bin\/bash\u201d \u53ef\u4ee5). Debian \u66fe\u7ecf\u91c7\u7528 \/bin\/bash \u66f4\u6539 \/bin\/dash\uff0c\u76ee\u7684\u4f7f\u7528\u66f4\u5c11\u7684\u78c1\u76d8\u7a7a\u95f4\u3001\u63d0\u4f9b\u8f83\u5c11\u7684\u529f\u80fd\u3001\u83b7\u53d6\u66f4\u5feb\u7684\u901f\u5ea6\u3002\u4f46\u662f\u540e\u6765\u7ecf\u8fc7 shell \u811a\u672c\u6d4b\u8bd5\u5b58\u5728\u8fd0\u884c\u95ee\u9898\u3002\u56e0\u4e3a\u539f\u5148\u5728 bash shell \u4e0b\u53ef\u4ee5\u8fd0\u884c\u7684 shell script (shell \u811a\u672c)\uff0c\u5728 \/bin\/sh \u4e0b\u8fd8\u662f\u4f1a\u51fa\u73b0\u4e00\u4e9b\u610f\u60f3\u4e0d\u5230\u7684\u95ee\u9898\uff0c\u4e0d\u662f100%\u7684\u517c\u7528\u3002<\/div>\n<\/div>\n<div><\/div>\n<div>\n<div>\n<div class=\"codeheads\">\n<p>\u70b9\u51fb(\u6b64\u5904)\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<\/div>\n<div id=\"code576\" class=\"codeText\">\n<ol class=\"dp-css\" start=\"1\">\n<li>1 a=12345<\/li>\n<li>2<\/li>\n<li>3\u00a0let\u00a0&#8220;a += 1&#8221;<\/li>\n<li>4 echo\u00a0&#8220;a = $a&#8221;<\/li>\n<li>5<\/li>\n<li>6 b=${a\/23\/BB}<\/li>\n<li>7 echo\u00a0&#8220;b = $b&#8221;<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<div>\n<div class=\"codeheads\">\n<p>\u70b9\u51fb(\u6b64\u5904)\u6298\u53e0\u6216\u6253\u5f00<\/p>\n<\/div>\n<div id=\"code878\" class=\"codeText\">\n<ol class=\"dp-css\" start=\"1\">\n<li>luotaijia@ubuntu:~\/\u6587\u6863\/shell\u5b66\u4e60\u7ec3\u4e60$\u00a0\/bin\/sh 3.2..1.sh<\/li>\n<li>3.2..1.sh:\u00a03:\u00a0let:\u00a0not\u00a0found<\/li>\n<li>a\u00a0=\u00a012345<\/li>\n<li>3.2..1.sh:\u00a06:\u00a0Bad substitution<\/li>\n<li>luotaijia@ubuntu:~\/\u6587\u6863\/shell\u5b66\u4e60\u7ec3\u4e60$\u00a0\/bin\/bash 3.2..1.sh<\/li>\n<li>a\u00a0=\u00a012346<\/li>\n<li>b\u00a0=\u00a01BB46<\/li>\n<li>luotaijia@ubuntu:~\/\u6587\u6863\/shell\u5b66\u4e60\u7ec3\u4e60$<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div>\u00a0 \u00a0\u00a0\u6ce8:\u00a0b=${a\/23\/BB} \u628a\u53d8\u91cfa\u4e2d\u768423(\u4ec5\u9650\u7b2c\u4e00\u6b21\u51fa\u73b0)\u66ff\u6362\u6210BB, \u5e76\u8d4b\u503c\u7ed9 b.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linux \u4e2d\u7684 shell \u6709\u5f88\u591a\u7c7b\u578b\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u51e0\u79cd\u662f: Bourne shell (sh)\u3001C shell (csh) \u548c Korn shell (ksh), \u5404\u6709\u4f18\u7f3a\u70b9\u3002Bourne shell \u662f UNIX \u6700\u521d\u4f7f\u7528\u7684 shell\uff0c\u5e76\u4e14\u5728\u6bcf\u79cd UNIX [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1213","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/1213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1213"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/1213\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}