{"id":3708,"date":"2012-01-30T15:48:55","date_gmt":"2012-01-30T07:48:55","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=3708"},"modified":"2012-01-30T15:48:55","modified_gmt":"2012-01-30T07:48:55","slug":"%e4%bb%8e%e4%bf%ae%e6%94%b9%e6%96%87%e4%bb%b6%e6%89%a9%e5%b1%95%e5%90%8d%e5%88%b0%e5%ad%90%e4%b8%b2%e5%88%a0%e9%99%a4","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/3708","title":{"rendered":"\u4ece\u4fee\u6539\u6587\u4ef6\u6269\u5c55\u540d\u5230\u5b50\u4e32\u5220\u9664"},"content":{"rendered":"<p>\u4e4b\u524d\u5728\u8fd9\u7bc7<a href=\"http:\/\/edsionte.com\/techblog\/archives\/3394\" target=\"_blank\">\u6587\u7ae0<\/a>\u4e2d\u5df2\u7ecf\u5217\u4e3e\u4e86\u4e00\u79cd\u901a\u7528\u7684\u6279\u91cf\u4fee\u6539\u6587\u4ef6\u540e\u7f00\u540d\u7684\u65b9\u6cd5\uff0c\u4eca\u5929\u770b\u5230\u53d8\u91cf\u66ff\u6362${var%pattern}\uff0c\u56e0\u6b64\u53c8\u6709\u4e0b\u9762\u7684\u4e00\u79cd\u65b9\u6cd5:<\/p>\n<pre class=\"brush:c\">\r\n#!\/bin\/bash\r\n\r\nif [ $# -ne 3 ]\r\nthen\r\n\techo \"Usage:$(basename $0) old_name new_name dir\"\r\n\texit -1\r\nfi\r\n\r\nold_name=\"$1\"\r\nnew_name=\"$2\"\r\ndir=\"$3\"\r\n\r\nfor file in $(ls *.$old_name)\r\ndo\r\n\tnewfile=${file%.$old_name}.$new_name\r\n\tmv $file $newfile\r\n\techo \"$file ===> $newfile\"\r\ndone\r\n\r\nexit 0\r\n<\/pre>\n<p>\u8be5\u811a\u672c\u7528\u5230\u4e86\u53d8\u91cf\u66ff\u6362\u4e2d\u7684\u5b50\u4e32\u5220\u9664\u65b9\u6cd5\uff1a${var%pattern}\u3002\u5b83\u7684\u4f5c\u7528\u662f\u4ece\u53d8\u91cf$var\u7684\u672b\u5c3e\u5220\u9664\u6700\u5c0f\u5339\u914d$pattern\u5b57\u7b26\u4e32\u3002\u4e0e\u6b64\u5bf9\u5e94\u7684\u65b9\u6cd5${var%%pattern}\u5219\u662f\u5220\u9664\u6700\u5927\u5339\u914d$pattern\u5b57\u4e32\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">\r\nedsionte@edsionte-laptop:~\/mytest$ var=abcd12345abc6789\r\nedsionte@edsionte-laptop:~\/mytest$ pattern=b*9\r\nedsionte@edsionte-laptop:~\/mytest$ echo \"${var%$pattern}\"\r\nabcd12345a\r\nedsionte@edsionte-laptop:~\/mytest$ echo \"${var%%$pattern}\"\r\na\r\n<\/pre>\n<p>\u5982\u679c\u60f3\u4ece\u53d8\u91cf$var\u5f00\u5934\u5220\u9664\u5b57\u7b26\u4e32$pattern\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528${var#pattern}\u5220\u9664\u6700\u5c0f\u5339\u914d\u7684\u5b57\u7b26\u4e32\uff0c\u800c${var##pattern}\u5219\u53ef\u4ee5\u5220\u9664\u6700\u5927\u5339\u914d$pattern\u7684\u5b57\u7b26\u4e32\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">\r\nedsionte@edsionte-laptop:~\/mytest$ var=abcd12345abc6789\r\nedsionte@edsionte-laptop:~\/mytest$ pattern=a*c\r\nedsionte@edsionte-laptop:~\/mytest$ echo \"${var#$pattern}\"\r\nd12345abc6789\r\nedsionte@edsionte-laptop:~\/mytest$ echo \"${var##$pattern}\"\r\n6789\r\n<\/pre>\n<p>\u4ece\u53d8\u91cf\u4e2d\u5220\u9664\u6307\u5b9a\u5b57\u7b26\u4e32\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u5df2\u7ecf\u5217\u4e3e\u4e86\u4e00\u79cd\u901a\u7528\u7684\u6279\u91cf\u4fee\u6539\u6587\u4ef6\u540e\u7f00\u540d\u7684\u65b9\u6cd5\uff0c\u4eca\u5929\u770b\u5230\u53d8\u91cf\u66ff\u6362${var%pattern}\uff0c\u56e0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[153],"tags":[155,305,306],"class_list":["post-3708","post","type-post","status-publish","format-standard","hentry","category-shell","tag-shell","tag-305","tag-306"],"views":5083,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=3708"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/3708\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=3708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=3708"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=3708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}