{"id":62070,"date":"2025-04-29T09:30:54","date_gmt":"2025-04-29T01:30:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/62070\/"},"modified":"2025-04-29T09:30:54","modified_gmt":"2025-04-29T01:30:54","slug":"bash-%e4%b8%ad%e7%9a%84-%e5%92%8c-%e6%9c%89%e4%bb%80%e4%b9%88%e5%8c%ba%e5%88%ab-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/62070\/","title":{"rendered":"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b"},"content":{"rendered":"<p>   <\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u50cf Linux \u8fd9\u6837\u7684\u57fa\u4e8e GNU \u7684\u64cd\u4f5c\u7cfb\u7edf\u4f9d\u8d56\u4e8e\u4e00\u4e2a\u540d\u4e3a Bash \u7684\u547d\u4ee4\u8bed\u8a00\u89e3\u91ca\u5668\u6216 Shell \u6765\u5b8c\u6210\u5b83\u4eec\u7684\u5927\u90e8\u5206\u8ba1\u7b97\u4efb\u52a1\u548c\u76ee\u6807\u3002<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/253bc555c62bd42a902704cc11ff6809-0.jpg\" class=\"aligncenter\" title=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe\" alt=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe\" \/><\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">Bash \u662f Bourne Again Shell \u7684\u7f29\u5199\uff0cBunne Again Shell \u662f\u4e00\u4e2a\u53cc\u5173\u7684\u540d\u79f0\uff0c\u662f\u5bf9 Bourne Shell (\u5373 Steven Bourne \u53d1\u660e)\u7684\u81f4\u656c\u3002\u5728\u517c\u5bb9\u6027\u65b9\u9762\uff0cBash \u548c sh \u662f\u7edd\u914d\u3002C shell ( csh ) \u548cKorn shell ( ksh ) \u4e2d\u660e\u663e\u7684\u6709\u7528\u7279\u6027\u4e5f\u5305\u542b\u5728\u8fd9\u4e2a shell \u8bed\u8a00\u89e3\u91ca\u5668\u4e2d\u3002<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5728\u5b9e\u73b0\u65b9\u9762\uff0cBash \u65e8\u5728\u7b26\u5408 IEEE POSIX \u89c4\u8303\uff08IEEE \u6807\u51c6 1003.1\uff09\u5de5\u5177\u90e8\u5206\u548c IEEE POSIX Shell\u3002\u56e0\u6b64\uff0c\u4f5c\u4e3a\u4e00\u79cd\u4ea4\u4e92\u5f0f\u548c\u7f16\u7a0b\u5de5\u5177\uff0cBash &nbsp;\u63d0\u4f9b\u7684\u529f\u80fd\u6539\u8fdb\u80dc\u8fc7 sh \u4e2d\u7684\u6539\u8fdb\u3002<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">Linux \u548c\u5176\u4ed6\u57fa\u4e8e GNU \u7684\u64cd\u4f5c\u7cfb\u7edf\u7684\u7528\u6237\u4e0d\u5fc5\u4ec5\u4ec5\u4f9d\u8d56Bash\u4f5c\u4e3a\u4ed6\u4eec\u7684\u4e3b\u8981\u547d\u4ee4\u8bed\u8a00\u89e3\u91ca\u5668\uff0c\u56e0\u4e3a\u50cf csh \u8fd9\u6837\u7684 shell \u7248\u672c\u4e5f\u9884\u5148\u6253\u5305\u5728\u8fd9\u4e9b\u7cfb\u7edf\u4e2d\u3002\u7531\u4e8e\u5176\u72ec\u7279\u7684 shell \u5c5e\u6027\uff08\u5982\u53ef\u79fb\u690d\u6027\uff09\uff0cBash \u4ec5\u914d\u7f6e\u4e3a\u7528\u4f5c\u9ed8\u8ba4 Linux shell\u3002<\/p>\n<h4><span style=\"font-size: inherit;color: inherit;line-height: inherit\">\u5728 Bash \u4e2d\u6bd4\u8f83 $() \u4e0e ${}<\/span><\/h4>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u4e3a\u4e86\u6bd4\u8f83\u4e0e Bash \u73af\u5883\u76f8\u5173\u7684\u8fd9\u4e24\u4e2a\u5c5e\u6027\uff0c\u6211\u4eec\u5fc5\u987b\u91cd\u7533$()to$(command)\u548c${}to ${parameter}\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u5c1d\u8bd5\u5b9a\u4e49\u8fd9\u4e24\u4e2a Bash \u5b9e\u4f53\u3002<\/p>\n<h4><span style=\"font-size: inherit;color: inherit;line-height: inherit\">\u7406\u89e3 $(\u547d\u4ee4)<\/span><\/h4>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">$(command)\u5728Bash\u4e2d\u6d89\u53ca\u547d\u4ee4\u66ff\u6362\u3002\u66f4\u5177\u4f53\u5730\u8bf4\uff0c\u547d\u4ee4\u90e8\u5206in$(command)\u88ab\u6267\u884c\uff0c\u5176\u8f93\u51fa\u88ab\u6355\u83b7\u5e76\u6253\u5370\u5728\u6807\u51c6\u8f93\u51fa\u4e0a\u3002<\/p>\n<pre>\u725b\u903c\u554a\uff01\u63a5\u79c1\u6d3b\u5fc5\u5907\u7684&nbsp;N&nbsp;\u4e2a\u5f00\u6e90\u9879\u76ee\uff01\u8d76\u5feb\u6536\u85cf<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u80cc\u540e\u7684\u8bed\u6cd5$(command)\u662f\u4ee4\u724c\u7ea7\u522b\u7684\u3002\u8003\u8651\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u65e8\u5728\u5728\u7ec8\u7aef\u4e0a\u6253\u5370\u51fa\u5f53\u524d\u65e5\u671f\u3002<\/p>\n<pre>echo&nbsp;\"\u4eca\u5929\u662f&nbsp;$(date).&nbsp;LinuxMi.com&nbsp;\u53c8\u662f\u7f8e\u597d\u7684\u4e00\u5929\u3002\"<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"font-family: system-ui, -apple-system, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/f148c19a5e77e578b41e20829f0d0dcb-1.png\" class=\"aligncenter\" title=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe1\" alt=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe1\" \/><\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5728 Linux \u4e2d\u6253\u5370\u65e5\u671f<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u4e0a\u8ff0\u6267\u884c\u53ef\u4ee5\u7528\u4ee5\u4e0b\u65b9\u5f0f\u89e3\u91ca\u3002\u9996\u5148\uff0c\u6267\u884c date \u547d\u4ee4\u5e76\u5c06\u5176\u8f93\u51fa\u4f5c\u4e3a\u53c2\u6570\u5305\u542b\u5728 echo \u547d\u4ee4\u4e2d\u3002<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u53ef\u4ee5\u5047\u8bbe\u547d\u4ee4\u66ff\u6362\u5728\u91cd\u65b0\u5305\u542b\u5728\u4e3b shell \u4e4b\u524d\u5728\u5355\u72ec\u7684\u5b50 shell \u4e2d\u6267\u884c\u3002<\/p>\n<h4><span style=\"font-size: inherit;color: inherit;line-height: inherit\">\u4e86\u89e3 ${parameter}<\/span><\/h4>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">${parameter}\u5728Bash\u4e2d\u6d89\u53ca\u53c2\u6570\u66ff\u6362\u3002\u6839\u636e Bash \u624b\u518c\u9875\uff0c\u53c2\u6570\u662f\u4e00\u4e2a\u503c\u5b58\u50a8\u5b9e\u4f53\u3002\u53c2\u6570\u5b9e\u4f53\u53ef\u4ee5\u4e0e\u540d\u79f0\u3001\u6570\u5b57\u6216\u7279\u6b8a\u5b57\u7b26\u76f8\u5173\u8054\u3002<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5927\u62ec\u53f7{}\u6697\u793a\u6211\u4eec\u5728\u5904\u7406\u4f4d\u7f6e\u53c2\u6570\uff0c\u6216\u8005\u5728\u4f7f\u7528\u7684\u53c2\u6570\uff08\u53c2\u6570\u503c\uff09\u540e\u9762\u662f\u4e00\u4e2a\u4e0e\u53c2\u6570\u540d\u79f0\u4e0d\u76f8\u5173\u7684\u975e\u89e3\u91ca\u6027\u5b57\u7b26\uff0c\u4f8b\u5982${animal}s\u3002<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u81f3\u4e8e\u4f4d\u7f6e\u53c2\u6570\uff0c\u53ef\u4ee5\u7528\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u5b57\u6765\u8868\u793a\uff08\u5355\u4e2a\u6570\u5b57 0 \u9664\u5916\uff09\u3002\u56e0\u6b64\uff0c\u5982\u679c\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a$variable_name\u7684\u53d8\u91cf\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u53c2\u6570 \u66ff\u6362${parameter}\u6765\u68c0\u7d22\u5173\u8054\u7684\u53d8\u91cf\u503c\u3002<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u8003\u8651\u4ee5\u4e0b\u53d8\u91cf\u58f0\u660e\u547d\u4ee4\uff1a<\/p>\n<pre>$&nbsp;animal=lion<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u8ba9\u6211\u4eec\u8c03\u7528 animal \u53d8\u91cf\u4ee5\u5c1d\u8bd5\u5c06\u53d8\u91cf\u503c\u590d\u6570\uff1a<\/p>\n<pre>$&nbsp;echo&nbsp;$animals<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"font-family: system-ui, -apple-system, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/f148c19a5e77e578b41e20829f0d0dcb-2.png\" class=\"aligncenter\" title=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe2\" alt=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe2\" \/><\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5728\u547d\u4ee4\u4e2d\u58f0\u660e\u53d8\u91cf<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5728\u6807\u51c6\u8f93\u51fa\u4e2d\u4e0d\u4f1a\u6253\u5370\u4efb\u4f55\u5185\u5bb9\uff0c\u56e0\u4e3a Bash \u4e0d\u7406\u89e3\u53d8\u91cf$animals\u3002\u4f46\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u4f7f\u7528\u53c2\u6570\u66ff\u6362\u65b9\u6cd5\u6210\u529f\u8c03\u7528\u6211\u4eec\u7684$animals\u53d8\u91cf:<\/p>\n<pre>$&nbsp;echo&nbsp;${animal}s<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"font-family: system-ui, -apple-system, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/35706975202af6bc53e60f6cf79f0643-3.png\" class=\"aligncenter\" title=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe3\" alt=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe3\" \/><\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5728\u547d\u4ee4\u4e2d\u8c03\u7528\u53d8\u91cf<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u611f\u53f9\u53f7\u53ef\u80fd\u4f1a\u5728\u53c2\u6570\u66ff\u6362\u5b9e\u73b0\u7684\u7b2c\u4e00\u4e2a\u5de6\u5927\u62ec\u53f7\u4e4b\u540e\u51fa\u73b0\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5c31\u4f1a\u51fa\u73b0\u53d8\u91cf\u95f4\u63a5\u7684\u6982\u5ff5\u3002\u53e6\u5916\uff0c\u641c\u7d22\u516c\u4f17\u53f7Linux\u5c31\u8be5\u8fd9\u6837\u5b66\u540e\u53f0\u56de\u590d\u201c\u7334\u5b50\u201d\uff0c\u83b7\u53d6\u4e00\u4efd\u60ca\u559c\u793c\u5305\u3002<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u53d8\u91cf\u503c\u4f18\u5148\u4e8e\u53c2\u6570\u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>$&nbsp;animal=lion&nbsp;\n$&nbsp;echo&nbsp;$animal\n$&nbsp;lion=rafiki\n$&nbsp;echo&nbsp;$lion\n$&nbsp;echo&nbsp;${!animal}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236    <\/p>\n<p style=\"font-family: system-ui, -apple-system, BlinkMacSystemFont,\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/275\/013\/35706975202af6bc53e60f6cf79f0643-4.png\" class=\"aligncenter\" title=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe4\" alt=\"Bash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u63d2\u56fe4\" \/><\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u53c2\u6570\u503c\u7684\u4f18\u5148\u7ea7<\/p>\n<p style=\"margin-top: 1.5em;margin-bottom: 1.5em;font-size: inherit;color: inherit;line-height: inherit\">\u5e0c\u671b\u672c\u6587\u80fd\u591f\u8bf4\u660e Bash \u4e2d$()\u548c${}\u4e4b\u95f4\u7684\u533a\u522b\u3002<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fBash \u4e2d\u7684 ${} \u548c $() \u6709\u4ec0\u4e48\u533a\u522b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u50cf Linux \u8fd9\u6837\u7684\u57fa\u4e8e GNU \u7684\u64cd\u4f5c\u7cfb\u7edf\u4f9d\u8d56\u4e8e\u4e00\u4e2a\u540d\u4e3a Bash \u7684\u547d\u4ee4\u8bed\u8a00\u89e3\u91ca\u5668\u6216 Shell \u6765\u5b8c\u6210\u5b83\u4eec\u7684\u5927\u90e8\u5206\u8ba1\u7b97\u4efb\u52a1\u548c\u76ee\u6807\u3002 Bash \u662f Bourne Again Shell \u7684\u7f29\u5199\uff0cBunne Again Shell \u662f\u4e00\u4e2a\u53cc\u5173\u7684\u540d\u79f0\uff0c\u662f\u5bf9 Bourne Shell (\u5373 Steven Bourne \u53d1\u660e)\u7684\u81f4\u656c\u3002\u5728\u517c\u5bb9\u6027\u65b9\u9762\uff0cBash \u548c sh \u662f\u7edd\u914d\u3002C shell ( csh ) \u548cKorn shell ( ksh ) \u4e2d\u660e\u663e\u7684\u6709\u7528\u7279\u6027\u4e5f\u5305\u542b\u5728\u8fd9\u4e2a shell \u8bed\u8a00\u89e3\u91ca\u5668\u4e2d\u3002 \u5728\u5b9e\u73b0\u65b9\u9762\uff0cBash \u65e8\u5728\u7b26\u5408 IEEE POSIX \u89c4\u8303\uff08IEEE \u6807\u51c6 1003.1\uff09\u5de5\u5177\u90e8\u5206\u548c IEEE POSIX Shell\u3002\u56e0\u6b64\uff0c\u4f5c\u4e3a\u4e00\u79cd\u4ea4\u4e92\u5f0f\u548c\u7f16\u7a0b\u5de5\u5177\uff0cBash &nbsp;\u63d0\u4f9b\u7684\u529f\u80fd\u6539\u8fdb\u80dc\u8fc7 sh \u4e2d\u7684\u6539\u8fdb\u3002 Linux \u548c\u5176\u4ed6\u57fa\u4e8e GNU [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-62070","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=62070"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62070\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=62070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=62070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=62070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}