{"id":121,"date":"2014-06-25T02:41:02","date_gmt":"2014-06-25T02:41:02","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=121"},"modified":"2014-06-25T02:41:02","modified_gmt":"2014-06-25T02:41:02","slug":"shell%e4%b8%ad%e9%a2%84%e5%85%88%e5%ae%9a%e4%b9%89%e7%9a%84%e7%89%b9%e6%ae%8a%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/121.html","title":{"rendered":"Shell\u4e2d\u9884\u5148\u5b9a\u4e49\u7684\u7279\u6b8a\u53d8\u91cf"},"content":{"rendered":"<p><span style=\"color: #454545;\">$#\u00a0 \u00a0 \u547d\u4ee4\u884c\u4e0a<span style=\"color: #ff0000;\"><strong>\u53c2\u6570\u7684\u4e2a\u6570<\/strong><\/span>\uff0c\u4f46\u4e0d\u5305\u542bshell\u811a\u672c\u540d\u672c\u8eab\u3002\u56e0\u6b64\uff0c$#\u53ef\u4ee5\u7ed9\u51fa\u5b9e\u9645\u53c2\u6570\u7684\u4e2a\u6570\u3002<\/span><\/p>\n<p><span style=\"color: #454545;\">$?\u00a0\u00a0 \u00a0<span style=\"color: #ff0000;\"><strong>\u4e0a\u4e00\u6761\u547d\u4ee4\u6267\u884c\u540e\u7684\u8fd4\u56de\u503c<\/strong><\/span>\uff08\u4e5f\u79f0\u4f5c\u00a0\u201c\u8fd4\u56de\u7801\u201d\u3001\u00a0\u201c\u9000\u51fa\u72b6\u6001\u201d\u3001\u201c\u9000\u51fa\u7801\u201d\u7b49\uff09\u3002\u5b83\u662f\u4e00\u4e2a\u5341\u8fdb\u5236\u6570\u3002<\/span><\/p>\n<p><span style=\"color: #454545;\">$$\u00a0\u00a0\u00a0\u00a0<span style=\"color: #ff0000;\">\u5f53\u524d\u8fdb\u7a0b\u7684\u8fdb\u7a0b\u53f7<\/span>\u3002<\/span><\/p>\n<p><span style=\"color: #454545;\">$!\u00a0 \u00a0 \u4e0a\u4e00\u4e2a\u540e\u53f0\u547d\u4ee4\u5bf9\u5e94\u7684\u8fdb\u7a0b\u53f7\uff0c\u8fd9\u662f\u4e00\u4e2a\u75311~5\u4f4d\u6570\u5b57\u6784\u6210\u7684\u6570\u5b57\u4e32\u3002<\/span><\/p>\n<p><span style=\"color: #454545;\">$-\u00a0 \u00a0 \u7531\u5f53\u524dshell\u8bbe\u7f6e\u7684\u6267\u884c\u6807\u5fd7\u540d\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002($ echo $- \u00a0#himBH)<\/span><\/p>\n<p><span style=\"color: #454545;\">$*\u00a0\u00a0\u00a0\u00a0\u8868\u793a\u5728\u547d\u4ee4\u884c\u4e2d\u5b9e\u9645\u7ed9\u51fa\u7684\u6240\u6709\u5b9e\u53c2\u5b57\u7b26\u4e32\uff0c\u5b83\u5e76\u4e0d\u4ec5\u9650\u4e8e9\u4e2a\u5b9e\u53c2\u3002<\/span><\/p>\n<p><span style=\"color: #454545;\">$@\u00a0\u00a0\u00a0\u00a0\u5b83\u4e0e$*\u57fa\u672c\u529f\u80fd\u76f8\u540c\uff0c\u5373\u8868\u793a\u5728\u547d\u4ee4\u884c\u4e2d\u7ed9\u51fa\u7684\u6240\u6709\u5b9e\u53c2\u3002\u4f46\u201c$@\u201d\u4e0e\u201c$*\u201d\u4e0d\u540c\u3002<\/span><\/p>\n<p>\u5728\u300aLinux\u7a0b\u5e8f\u8bbe\u8ba1\u300b\u91cc\u63a8\u8350\u4f7f\u7528 $@\uff0c\u800c\u4e0d\u662f$*\uff0c\u56e0\u4e3a$*\u5bb9\u6613\u53d7\u5230IFS\u53d8\u91cf\u7684\u5f71\u54cd\u3002<\/p>\n<pre class=\"lang:default decode:true  \">$@\t\u4f4d\u7f6e\u53c2\u6570\u4ece \u53c2\u65701($1) \u5f00\u59cb\u3002\u5982\u679c\u5728\u53cc\u5f15\u53f7\u4e2d\u8fdb\u884c\u6269\u5c55\uff0c\u5219\u6bcf\u4e2a\u53c2\u6570\u90fd\u4f1a\u6210\u4e3a\u4e00\u4e2a\u8bcd\uff0c\u56e0\u6b64 \"$@\" \u4e0e \"$1\" \"$2\" \u7b49\u6548\u3002\u5982\u679c\u53c2\u6570\u6709\u53ef\u80fd\u5305\u542b\u5d4c\u5165\u7a7a\u767d\uff0c\u90a3\u4e48\u60a8\u5c06\u9700\u8981\u4f7f\u7528\u8fd9\u79cd\u5f62\u5f0f(\"$@\")\u3002\n\n$*\t\u4f4d\u7f6e\u53c2\u6570\u4ece \u53c2\u65701($1) \u5f00\u59cb\u3002\"$*\" \u6269\u5c55\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u8bcd\u3002\u6839\u636e IFS \u8fdb\u884c\u5206\u5272(\"$*\" is one long string and $IFS act as an separator or token delimiters.)\u3002\n\n$@ expanded as \"$1\" \"$2\" \"$3\" ... \"$n\"\n$* expanded as \"$1y$2y$3y...$n\", where y is the value of $IFS variable\n\n\u603b\u7ed3\uff1a\u63a8\u8350\u5728\u811a\u672c\u4e2d\u4f7f\u7528 \"$@\" (\u8981\u8bb0\u5f97\u5e26\u4e0a\u5f15\u53f7)\u3002<\/pre>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/blog.csdn.net\/whuslei\/article\/details\/7187639\" target=\"_blank\">Shell\u4e2d\u7684IFS\u89e3\u60d1<\/a><\/li>\n<li><a href=\"http:\/\/smilejay.com\/2011\/12\/bash_ifs\/\" target=\"_blank\">shell\u4e2d\u7684IFS\u8be6\u89e3<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>$#\u00a0 \u00a0 \u547d\u4ee4\u884c\u4e0a\u53c2\u6570\u7684\u4e2a\u6570\uff0c\u4f46\u4e0d\u5305\u542bshell\u811a\u672c\u540d\u672c\u8eab\u3002\u56e0\u6b64\uff0c$#\u53ef\u4ee5\u7ed9\u51fa\u5b9e\u9645\u53c2\u6570\u7684\u4e2a\u6570\u3002 $?\u00a0\u00a0 \u00a0 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[65],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-linux","tag-shell"],"views":4308,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/121","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=121"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}