{"id":13880,"date":"2015-06-04T03:03:37","date_gmt":"2015-06-03T18:03:37","guid":{"rendered":"http:\/\/arison.jp\/blog\/?p=13880"},"modified":"2017-06-18T23:45:00","modified_gmt":"2017-06-18T14:45:00","slug":"bash-shell-parameter-expansion-or-cut","status":"publish","type":"post","link":"https:\/\/arison.jp\/blog\/2015\/06\/04\/bash-shell-parameter-expansion-or-cut\/","title":{"rendered":"bash\u3067\u5909\u6570\u306e\u4e00\u90e8\u3092\u629c\u304d\u51fa\u3059\u6642\u306f\u30d1\u30e9\u30e1\u30bf\u5c55\u958b\u3067"},"content":{"rendered":"<p><strong>bash\u4f7f\u3063\u3066\u3066\u3001\u3042\u308b\u5909\u6570\u306e\u4e00\u90e8\u3092\u629c\u304d\u51fa\u3059\u51e6\u7406\u3092\u884c\u3046\u6642\u306f<br \/>\n\u30d1\u30e9\u30e1\u30bf\u5c55\u958b(Shell Parameter Expansion)\u3092\u4f7f\u3046\u3079\u3057\u3002<br \/>\ncut \u306f\u4f7f\u308f\u306a\u3044\u3053\u3068\u3002<\/strong><\/p>\n<p>1\u30ec\u30b3\u30fc\u30c91\u884c\u3067\u56fa\u5b9a\u9577\u306e\u30c7\u30fc\u30bf\u3092\u7de8\u96c6\u3057\u305f\u3044\u3068\u304d\u3001<br \/>\n\u30b7\u30f3\u30d7\u30eb\u306b\u8003\u3048\u305f\u3089\u30011\u884c\u3092\u8aad\u307f\u8fbc\u3093\u3067\u4f55\u3089\u304b\u306e\u5909\u6570\u306b\u683c\u7d0d\u3057\u3066<br \/>\n\u5909\u6570\u306e\u4f55\u6841\u76ee\u304b\u3089\u4f55\u6841\u76ee\u3092\u629c\u3044\u3066\u3001\u6761\u4ef6\u306b\u5fdc\u3058\u3066\u3001\u307b\u3052\u307b\u3052\u30fb\u30fb\u30fb\u307f\u305f\u3044\u306a\u3053\u3068\u3092\u3059\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u305d\u3093\u306a\u3068\u304d\u3001\u3042\u308b\u5909\u6570\u306e\u4e00\u90e8\u3092\u629c\u304d\u51fa\u3057\u3066\u5909\u6570\u306b\u683c\u7d0d\u3059\u308b\u5834\u5408<\/p>\n<p>cut\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3000(\u3068\u3000\u30d1\u30e9\u30e1\u30bf\u5c55\u958b)\u3000\u304c\u3056\u3063\u3068\u601d\u3044\u3064\u304d\u307e\u3057\u305f\u3002<br \/>\n\u2026\u30d1\u30e9\u30e1\u30bf\u5c55\u958b\u306fcut\u30b3\u30de\u30f3\u30c9\u3067\u6642\u9593\u304b\u304b\u308a\u3059\u304e\u305f\u306e\u3067\u63a1\u7528\u3057\u305f\u3002<\/p>\n<p><strong>cut\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5<\/strong><br \/>\n[shell]<br \/>\nhoge=&quot;\/\/arison.jp&quot; <\/p>\n<p>work=`echo ${hoge} | cut -c 2-4 `<\/p>\n<p>echo ${work}<\/p>\n<p>ris<br \/>\n[\/shell]<br \/>\n\u307f\u305f\u3044\u306a\u611f\u3058\u3067\u3084\u308b\u3068\u3001\u5909\u6570work\u306b\u5909\u6570hoge\u306e2\u6587\u5b57\u76ee\u304b\u30894\u6587\u5b57\u76ee\u307e\u3067\u304c\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<p>\u3067\u3082\u3001\u3053\u308c\u3060\u3068\u9045\u3044\u3002<\/p>\n<p><strong>\u30d1\u30e9\u30e1\u30bf\u5c55\u958b<\/strong><br \/>\nBash Reference Manual<br \/>\n<a href=\"http:\/\/www.gnu.org\/software\/bash\/manual\/bash.html\">http:\/\/www.gnu.org\/software\/bash\/manual\/bash.html<\/a><br \/>\n3.5.3 Shell Parameter Expansion\u3000\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u308b\u65b9\u6cd5<\/p>\n<p>\u30d1\u30e9\u30e1\u30bf\u5c55\u958b(Shell Parameter Expansion)\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5<br \/>\n[shell]<br \/>\nhoge=&quot;\/\/arison.jp&quot; <\/p>\n<p>work=${hoge : 1 3}<\/p>\n<p>echo ${work}<\/p>\n<p>ris<br \/>\n[\/shell]<br \/>\n\u3092\u4f7f\u3046\u307b\u3046\u304c\u30d0\u30ea\u65e9\u3067\u3057\u305f\u3002<\/p>\n<p>cut\u304c\u9045\u3044\u539f\u56e0\u306f`\uff5e`\u306b\u3042\u308a\u3002<br \/>\n`(\u30d0\u30c3\u30af\u30af\u30a9\u30fc\u30c8)\u3092\u7528\u3044\u308b\u3068\u3001\u30b3\u30de\u30f3\u30c9\u306e\u5b9f\u884c\u7d50\u679c\u3092\u5909\u6570\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u3066\u4fbf\u5229\u3067\u3059\u3002<br \/>\n\u304c\u3001\u30b3\u30de\u30f3\u30c9\u306e\u5b9f\u884c\u7d50\u679c\u3092\u3068\u308b\u305f\u3081\u306b\u5225\u30d7\u30ed\u30bb\u30b9\u3092\u7acb\u3061\u3042\u3052\u3066\u5b9f\u884c\u3059\u308b\u305f\u3081\u30d7\u30ed\u30bb\u30b9\u306e fork \u304c\u5fc5\u8981\u3002<br \/>\n\u3067\u3001fork \u306e\u30b3\u30b9\u30c8\u306f\u76f8\u5f53\u9ad8\u3044\u3002\u3088\u3063\u3066\u51e6\u7406\u304c\u9045\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4e00\u65b9\u3001\u30d1\u30e9\u30e1\u30bf\u5c55\u958b\u306f\u81ea\u5206\u81ea\u8eab\u3067\u3084\u3063\u3061\u3083\u3046\u3002<\/p>\n<p>\u91ce\u83dc\u7092\u3081\u4f5c\u308b\u3068\u304d\u306b<br \/>\n\u4ed6\u4eba\u306b\u91ce\u83dc\u5207\u3063\u3068\u3044\u3066\u3068\u983c\u3093\u3067\u3001\u5207\u3089\u308c\u305f\u91ce\u83dc\u3092\u3082\u3089\u3046\u3088\u308a\u3001<br \/>\n\u81ea\u5206\u3067\u91ce\u83dc\u3092\u5207\u3063\u305f\u307b\u3046\u304c\u65e9\u3044<br \/>\n\u305d\u3093\u306a\u611f\u3058\u3067\u53d7\u3051\u6b62\u3081\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u3001\u7d50\u679c\u306f\u540c\u3058\u3060\u3051\u3069\u3001cut\u3068Shell Parameter Expansion\u3067\u306f\u6570\u5b57\u304c\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>cut \u306e\u5834\u5408\u306f1\u6587\u5b57\u76ee\u3092\u3068\u308a\u305f\u3044\u5834\u5408\u306f1\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u30d1\u30e9\u30e1\u30bf\u5c55\u958b\u306e\u5834\u5408\u306f1\u6587\u5b57\u76ee\u3092\u3068\u308a\u305f\u3044\u5834\u5408\u306f0\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\uff08\u914d\u5217\u304c0\u304b\u3089\u306f\u3058\u307e\u308b\u3068\u3044\u3046\u30a2\u30ec\u3067\u3059\uff09<\/p>\n<p>\u958b\u59cb\u3068\u7d42\u4e86\u306e\u7bc4\u56f2\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5<br \/>\n\u3000cut \u306e\u5834\u5408\u306f\u300c\u958b\u59cb\u4f4d\u7f6e-\u7d42\u4e86\u4f4d\u7f6e\u300d\u3002<br \/>\n\u3000\u30d1\u30e9\u30e1\u30bf\u5c55\u958b\u306e\u5834\u5408\u306f\u300c\u958b\u59cb\u4f4d\u7f6e\u3000\u958b\u59cb\u4f4d\u7f6e\u304b\u3089\u306e\u6587\u5b57\u6570\u300d\u3002<\/p>\n<hr \/>\n<p>cut\u306e\u65b9\u304c\u3001\u30d1\u30e9\u30e1\u30bf\u5c55\u958b\u3088\u308a\u3001\u5f15\u6570\u306e\u4e0e\u3048\u65b9\u304c\u308f\u304b\u308a\u3084\u3059\u3044\u3068\u500b\u4eba\u7684\u306b\u306f\u611f\u3058\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>cut\u30b3\u30de\u30f3\u30c9\u306e\u8a73\u7d30\u306f\u4e0b\u8a18\u3092\u53c2\u8003\u3002<br \/>\n\u30b7\u30a7\u30eb\u30fb\u30b9\u30af\u30ea\u30d7\u30c8\u30fb\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9 &#8211; \u3010 \u6587\u5b57\u5217\u3092\u629c\u304d\u51fa\u3059\u300ccut\u300d \u3011\uff1aITpro<br \/>\n<a href=\"http:\/\/itpro.nikkeibp.co.jp\/article\/COLUMN\/20060228\/231159\/\">http:\/\/itpro.nikkeibp.co.jp\/article\/COLUMN\/20060228\/231159\/<\/a><\/p>\n<p>-b \u30d0\u30a4\u30c8\u6570 \u6307\u5b9a\u3057\u305f\u30d0\u30a4\u30c8\u6570\u306e\u6587\u5b57\u3092\u53d6\u308a\u51fa\u3059\u3002\u30d0\u30a4\u30c8\u306e\u6307\u5b9a\u306b\u306f\u300c\u958b\u59cb\u4f4d\u7f6e-\u7d42\u4e86\u4f4d\u7f6e\u300d\u306e\u3088\u3046\u306b\u7bc4\u56f2\u3067\u6307\u5b9a\u3067\u304d\u308b<br \/>\n-c \u6587\u5b57\u6570 \u6307\u5b9a\u3057\u305f\u6587\u5b57\u6570\u306e\u6587\u5b57\u3092\u53d6\u308a\u51fa\u3059\u3002\u6587\u5b57\u6570\u306e\u6307\u5b9a\u306b\u306f\u300c\u958b\u59cb\u4f4d\u7f6e-\u7d42\u4e86\u4f4d\u7f6e\u300d\u306e\u3088\u3046\u306b\u7bc4\u56f2\u3067\u6307\u5b9a\u3067\u304d\u308b <\/p>\n<p>-d &#8220;, &#8221; \u30c7\u30df\u30ea\u30bf\uff08\u533a\u5207\u308a\u6587\u5b57\uff09\u3092\u6307\u5b9a\u3059\u308b\u3002<br \/>\n-f \u30d5\u30a3\u30fc\u30eb\u30c9 \u6307\u5b9a\u3057\u305f\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u6587\u5b57\u3092\u53d6\u308a\u51fa\u3059\u3002\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u6307\u5b9a\u306b\u306f\u300c\u958b\u59cb\u4f4d\u7f6e-\u7d42\u4e86\u4f4d\u7f6e\u300d\u306e\u3088\u3046\u306b\u7bc4\u56f2\u3067\u6307\u5b9a\u3067\u304d\u308b <\/p>\n<p>\u3044\u308d\u3093\u306a\u629c\u304d\u51fa\u3057\u65b9\u6cd5\u304c\u3067\u304d\u308b\u3057\u3001\u8907\u6570\u884c\u6271\u3048\u308b\u306e\u3067\u3001cut\u81ea\u4f53\u306f\u7d20\u6674\u3089\u3057\u3044\u30b3\u30de\u30f3\u30c9\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<hr \/>\n<p>Shell Parameter Expansion\u3000\u306f\u3001\u3044\u308d\u3044\u308d\u3067\u304d\u308b\u5206\u3001\u308f\u304b\u308a\u3065\u3089\u3044\u3002<\/p>\n<p>\u516c\u5f0f\u306b\u306f\u8aac\u660e\u3059\u308b\u305f\u3081\u306b\u3001\u3053\u3093\u306a\u306b\u305f\u304f\u3055\u3093\u66f8\u3044\u3066\u3044\u3066\u30fb\u30fb\u30fb<br \/>\n[shell]<br \/>\n$ string=01234567890abcdefgh<br \/>\n$ echo ${string:7}<br \/>\n7890abcdefgh<br \/>\n$ echo ${string:7:0}<\/p>\n<p>$ echo ${string:7:2}<br \/>\n78<br \/>\n$ echo ${string:7:-2}<br \/>\n7890abcdef<br \/>\n$ echo ${string: -7}<br \/>\nbcdefgh<br \/>\n$ echo ${string: -7:0}<\/p>\n<p>$ echo ${string: -7:2}<br \/>\nbc<br \/>\n$ echo ${string: -7:-2}<br \/>\nbcdef<br \/>\n$ set &#8212; 01234567890abcdefgh<br \/>\n$ echo ${1:7}<br \/>\n7890abcdefgh<br \/>\n$ echo ${1:7:0}<\/p>\n<p>$ echo ${1:7:2}<br \/>\n78<br \/>\n$ echo ${1:7:-2}<br \/>\n7890abcdef<br \/>\n$ echo ${1: -7}<br \/>\nbcdefgh<br \/>\n$ echo ${1: -7:0}<\/p>\n<p>$ echo ${1: -7:2}<br \/>\nbc<br \/>\n$ echo ${1: -7:-2}<br \/>\nbcdef<br \/>\n$ array[0]=01234567890abcdefgh<br \/>\n$ echo ${array[0]:7}<br \/>\n7890abcdefgh<br \/>\n$ echo ${array[0]:7:0}<\/p>\n<p>$ echo ${array[0]:7:2}<br \/>\n78<br \/>\n$ echo ${array[0]:7:-2}<br \/>\n7890abcdef<br \/>\n$ echo ${array[0]: -7}<br \/>\nbcdefgh<br \/>\n$ echo ${array[0]: -7:0}<\/p>\n<p>$ echo ${array[0]: -7:2}<br \/>\nbc<br \/>\n$ echo ${array[0]: -7:-2}<br \/>\nbcdef<br \/>\n[\/shell]<\/p>\n<p>\u30fb\u30fb\u30fb\u3081\u3063\u3061\u3083\u4e01\u5be7\u306b\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002<br \/>\n\u4ed6\u306b\u3082\u7279\u6b8a\u306a\u53c2\u7167\u65b9\u6cd5\u304c\u3042\u308b\u306e\u3067\u3001\u899a\u3048\u3066\u3089\u308c\u306a\u3044\u3002<\/p>\n<p>\u305d\u308c\u3088\u308a\u306f\u3001\u4e0b\u3092\u307f\u305f\u307b\u3046\u304c\u308f\u304b\u308a\u3084\u3059\u3044\u3002<\/p>\n<p>\u30b9\u30c6\u30c3\u30d7\u30fb\u30d0\u30a4\u30fb\u30b9\u30c6\u30c3\u30d7\u30fb\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\uff085\uff09\uff1a\u30b7\u30a7\u30eb\u306e\u5909\u6570\u306b\u6163\u308c\u308b &#8211; \uff20IT<br \/>\n<a href=\"http:\/\/www.atmarkit.co.jp\/ait\/articles\/0010\/19\/news003.html\">http:\/\/www.atmarkit.co.jp\/ait\/articles\/0010\/19\/news003.html<\/a><\/p>\n<p>\u4f55\u5341\u4e07\u30ec\u30b3\u30fc\u30c9\u3068\u304b\u306e\u30c7\u30fc\u30bf\u3092\u6271\u3046\u3068\u3001\u3061\u3087\u3063\u3068\u306e\u5dee\u3067\u3082\u5927\u304d\u306a\u5dee\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u3002<br \/>\n\u30d0\u30c3\u30c1\u51e6\u7406\u306a\u3069\u3067\u3001\u3042\u308b\u5909\u6570\u306e\u4e00\u90e8\u3092\u629c\u304d\u51fa\u3059\u51e6\u7406\u3092\u884c\u3046\u6642\u306f\u30d1\u30e9\u30e1\u30bf\u5c55\u958b(Shell Parameter Expansion)\u3092\u4f7f\u3046\u3079\u3057\u3002<\/p>\n<p>\u901f\u5ea6\u6bd4\u8f03\u3057\u3066\u3044\u308b\u30b5\u30a4\u30c8\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3010\u53c2\u8003\u30b5\u30a4\u30c8\u3011<br \/>\ncut\u30b3\u30de\u30f3\u30c9\u3067\u6587\u5b57\u5217\u3092\u629c\u304d\u51fa\u3059\uff1f \u3061\u3087\u3063\u3068\u5f85\u3063\u3066\uff01Bash\u30d1\u30e9\u30e1\u30fc\u30bf\u5c55\u958b\u3067\uff17\uff12\u500d\u65e9\u304f\u3067\u304d\u308b\u304b\u3082<br \/>\n<a href=\"http:\/\/netbuffalo.doorblog.jp\/archives\/4270874.html\">http:\/\/netbuffalo.doorblog.jp\/archives\/4270874.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>bash\u4f7f\u3063\u3066\u3066\u3001\u3042\u308b\u5909\u6570\u306e\u4e00\u90e8\u3092\u629c\u304d\u51fa\u3059\u51e6\u7406\u3092\u884c\u3046\u6642\u306f \u30d1\u30e9\u30e1\u30bf\u5c55\u958b(Shell Parameter Expansion)\u3092\u4f7f\u3046\u3079\u3057\u3002 cut \u306f\u4f7f\u308f\u306a\u3044\u3053\u3068\u3002 1\u30ec\u30b3\u30fc\u30c91\u884c\u3067\u56fa\u5b9a\u9577\u306e\u30c7\u30fc\u30bf\u3092\u7de8\u96c6\u3057\u305f\u3044\u3068\u304d\u3001 \u30b7\u30f3\u30d7 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":7027,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-13880","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/posts\/13880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/comments?post=13880"}],"version-history":[{"count":0,"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/posts\/13880\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/media\/7027"}],"wp:attachment":[{"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/media?parent=13880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/categories?post=13880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arison.jp\/blog\/wp-json\/wp\/v2\/tags?post=13880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}