{"id":6718,"date":"2020-03-18T14:27:26","date_gmt":"2020-03-18T06:27:26","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=6718"},"modified":"2020-05-23T21:26:30","modified_gmt":"2020-05-23T13:26:30","slug":"shift","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/shift","title":{"rendered":"shift\u547d\u4ee4 – \u79fb\u52a8\u4f4d\u7f6e\u53c2\u6570"},"content":{"rendered":"\n
shift\u547d\u4ee4\u7528\u4e8e\u5bf9\u53c2\u6570\u7684\u79fb\u52a8(\u5de6\u79fb)\uff0c\u901a\u5e38\u7528\u4e8e\u5728\u4e0d\u77e5\u9053\u4f20\u5165\u53c2\u6570\u4e2a\u6570\u7684\u60c5\u51b5\u4e0b\u4f9d\u6b21\u904d\u5386\u6bcf\u4e2a\u53c2\u6570\u7136\u540e\u8fdb\u884c\u76f8\u5e94\u5904\u7406\uff08\u5e38\u89c1\u4e8eLinux\u4e2d\u5404\u79cd\u7a0b\u5e8f\u7684\u542f\u52a8\u811a\u672c\uff09\u3002<\/p>\n\n\n\n
\u5bf9\u4e8e\u67d0\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u5176\u53c2\u6570\u4e2a\u6570\u53ef\u4ee5\u4e0d\u56fa\u5b9a\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7$*\u6216$@\u8fdb\u884c\u5faa\u73af\u64cd\u4f5c\u3002\u82e5\u7528\u6237\u8981\u6c42Shell\u5728\u4e0d\u77e5\u9053\u53d8\u91cf\u4e2a\u6570\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd8\u80fd\u9010\u4e2a\u5904\u7406\u53c2\u6570\uff0c\u4e5f\u5c31\u662f\u5728$1\u4e4b\u540e\u662f$2\uff0c$2\u4e4b\u540e\u662f$3\u3002\u5728\u672a\u8fd0\u884cshift\u547d\u4ee4\u4e4b\u524d$1\u662f\u53ef\u7528\u7684\uff0c\u5f53\u4f7f\u7528shift\u547d\u4ee4\u4e4b\u540e\uff0c\u539f\u6765\u7684$2\u4f1a\u53d8\u6210$1\uff0c\u5e76\u4e14\u539f\u6709\u7684$1\u53d8\u5f97\u4e0d\u53ef\u7528\uff0c\u901a\u8fc7$#\u547d\u4ee4\u83b7\u5f97\u7684\u53c2\u6570\u4e2a\u6570\u4e5f\u4f1a\u5c111\u3002<\/p>\n\n\n\n
\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>shift [\u53c2\u6570]<\/p>\n\n\n\n \u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n \u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n \u4f9d\u6b21\u8bfb\u53d6\u8f93\u5165\u7684\u53c2\u6570\u5e76\u6253\u5370\u53c2\u6570\u4e2a\u6570\uff1a<\/p>\n\n\n\n run.sh \u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n \u628a\u53c2\u6570\u8fdb\u884c\u5de6\u79fb3\u4e2a\uff1a<\/p>\n\n\n\n \u5c06\u53c2\u6570\u4ece\u5de6\u5230\u53f3\u9010\u4e2a\u79fb\u52a8\uff1a<\/p>\n\n\n\n shift\u547d\u4ee4\u7528\u4e8e\u5bf9\u53c2\u6570\u7684\u79fb\u52a8(\u5de6\u79fb)\uff0c\u901a\u5e38\u7528\u4e8e\u5728\u4e0d\u77e5\u9053\u4f20\u5165\u53c2\u6570\u4e2a\u6570\u7684\u60c5\u51b5\u4e0b\u4f9d\u6b21\u904d\u5386\u6bcf\u4e2a\u53c2\u6570\u7136\u540e\u8fdb\u884c\u76f8\u5e94\u5904\u7406\uff08 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/6718"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=6718"}],"version-history":[{"count":9,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/6718\/revisions"}],"predecessor-version":[{"id":7372,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/6718\/revisions\/7372"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=6718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=6718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=6718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} n <\/td> \u6574\u6570<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n #!\/bin\/bash\nwhile [ $# != 0 ];do\necho \"\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\uff1a$1,\u53c2\u6570\u4e2a\u6570\u4e3a\uff1a$#\"\nshift\ndone \n\u8f93\u5165\u5982\u4e0b\u547d\u4ee4\u8fd0\u884c\uff1arun.sh a b c d e f \n\u7ed3\u679c\u663e\u793a\u5982\u4e0b\uff1a\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\uff1aa,\u53c2\u6570\u4e2a\u6570\u4e3a\uff1a6\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\uff1ab,\u53c2\u6570\u4e2a\u6570\u4e3a\uff1a5\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\uff1ac,\u53c2\u6570\u4e2a\u6570\u4e3a\uff1a4\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\uff1ad,\u53c2\u6570\u4e2a\u6570\u4e3a\uff1a3\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\uff1ae,\u53c2\u6570\u4e2a\u6570\u4e3a\uff1a2\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a\uff1af,\u53c2\u6570\u4e2a\u6570\u4e3a\uff1a1 <\/pre>\n\n\n\n
#!\/bin\/bash\necho -e \".\/t.sh arg1 arg2 arg3 arg4 arg5 arg6\"\nstr1=\"${1},${2},${3}\"\necho \"str1=$str1\"\nshift 3\nstr2=$@\necho \"str2=$str2\"\nsh t.sh 1 2 3 4 5 6 7\nstr1=1,2,3<\/pre>\n\n\n\n
[root@linuxcool ~]# cat shift.sh\n#!\/bin\/bash\nwhile [ $# -ne 0 ]\ndo\necho \"\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a: $1 \u53c2\u6570\u4e2a\u6570\u4e3a: $#\"\nshift\ndone\n[root@linuxcool ~]# sh shift.sh Lily Lucy Jake Mike\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a: Lily \u53c2\u6570\u4e2a\u6570\u4e3a: 4\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a: Lucy \u53c2\u6570\u4e2a\u6570\u4e3a: 3\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a: Jake \u53c2\u6570\u4e2a\u6570\u4e3a: 2\n\u7b2c\u4e00\u4e2a\u53c2\u6570\u4e3a: Mike \u53c2\u6570\u4e2a\u6570\u4e3a: 1<\/pre>\n","protected":false},"excerpt":{"rendered":"