{"id":1281,"date":"2013-12-09T00:31:27","date_gmt":"2013-12-08T15:31:27","guid":{"rendered":"http:\/\/kazu.tv\/blog\/?p=1281"},"modified":"2013-12-09T00:31:27","modified_gmt":"2013-12-08T15:31:27","slug":"bash-dollar-sign","status":"publish","type":"post","link":"https:\/\/kazu.tv\/blog\/2013\/12\/09\/bash-dollar-sign\/","title":{"rendered":"bash\u306e\u30c9\u30eb\u8a18\u53f7\u306e\u7528\u6cd5\u3092\u3044\u304f\u3064\u304b"},"content":{"rendered":"<p>bash\u3067\u306f\u30c9\u30eb\u8a18\u53f7\uff08$\uff09\u3067\u8272\u3005\u306a\u5834\u9762\u3067\u4f7f\u3046\uff08Bourne shell\u3067\u3082\u4f7f\u3046\u3051\u3069\uff09\u3002\u81ea\u5206\u304c\u77e5\u3063\u3066\u308b\u7bc4\u56f2\u3067\u307e\u3068\u3081\u3066\u307f\u305f\u3002<\/p>\n<h2>\u5909\u6570\u306e\u53c2\u7167<\/h2>\n<p>\u57fa\u672c\u4e2d\u306e\u57fa\u672c\u306a\u3093\u3067\u6562\u3048\u3066\u66f8\u304f\u5fc5\u8981\u306f\u306a\u3044\u304b\u3082\u3002<\/p>\n<pre class=\"brush: shell;\">foo=1234       # \u5909\u6570\u306e\u5b9a\u7fa9\r\necho $foo      # \u5909\u6570\u306e\u53c2\u7167\r\nary=(1 2 3)    # \u914d\u5217\u306e\u5b9a\u7fa9\r\necho ${ary[1]} # \u914d\u5217\u306e\u8981\u7d20\u306e\u53c2\u7167\r\nfor e in ${ary[@]} .... # \u914d\u5217\u5168\u4f53\u306e\u53c2\u7167<\/pre>\n<p><!--more--><\/p>\n<h2>\u30b3\u30de\u30f3\u30c9\u7f6e\u63db<\/h2>\n<p>\u3053\u308c\u304c\u300c\u30b3\u30de\u30f3\u30c9\u7f6e\u63db\uff08command substitution\uff09\u300d\u3068\u547c\u3076\u3063\u3066\u4e8b\u3092\u3001\u3053\u306e\u30d6\u30ed\u30b0\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u66f8\u3044\u3066\u308b\u6642\u306b\u521d\u3081\u3066\u77e5\u3063\u305f\u3002\u8981\u306f\u3001\u30b3\u30de\u30f3\u30c9\u3092\u5148\u306b\u5b9f\u884c\u3057\u3066\u3001\u305d\u306e\u7d50\u679c\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u8a55\u4fa1\u3059\u308b\u3063\u3066\u3084\u3064\u3002<\/p>\n<pre class=\"brush: shell;\">mkdir $(date +'%Y%m%d')\r\nmkdir `date +'%Y%m%d'`   # \u6614\u306f\u30d0\u30c3\u30af\u30af\u30a9\u30fc\u30c8\u3092\u4f7f\u3063\u3066\u3044\u305f\r\nfiles=($(ls)) # \u30b3\u30de\u30f3\u30c9\u306e\u7d50\u679c\u3092\u914d\u5217\u306b<\/pre>\n<h2>expr\u306e\u4ee3\u308f\u308a<\/h2>\n<p>\u6570\u5024\u8a08\u7b97\u3092\u3059\u308b\u6642\u3001\u6614\u306fexpr\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3063\u3066\u305f\u6c17\u304c\u3059\u308b\u3051\u3069\u3001\u3053\u3093\u306a\u3084\u308a\u65b9\u304c\u3042\u308b\u306e\u306d\u3002<\/p>\n<pre class=\"brush: shell;\">a=$((2 * 3))     # \u7c21\u5358\uff01\r\na=`expr 2 \\* 3`  # * \u304c\u5c55\u958b\u3055\u308c\u308b\u306e\u3092\u9632\u3050\u305f\u3081\u306b \\ \u304c\u5fc5\u8981<\/pre>\n<h2>\u30a8\u30b9\u30b1\u30fc\u30d7\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u8a55\u4fa1<\/h2>\n<p>\\n\u3092\u6539\u884c\u3068\u3057\u3066\u6271\u3063\u305f\u308a\u3001\u305d\u3046\u3044\u3046\u3084\u3064\u3002<\/p>\n<pre class=\"brush: shell;\">echo line 1$'\\n'line 2  # $'\\n' \u304c\u6539\u884c\u3092\u8868\u3059\r\nIFS=$'\\n'<\/pre>\n<h2>\u6587\u5b57\u5217\u306e\u524a\u9664<\/h2>\n<p>\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u4e00\u90e8\u3092\u524a\u9664\u3068\u304b\u306b\u4f7f\u3063\u305f\u308a\u3002<\/p>\n<pre class=\"brush: shell;\">a=abc123.def.456\r\necho ${a#*.}      # .\u4ee5\u524d\u3092\u524a\u9664 (\u6700\u77ed\u4e00\u81f4)\r\necho ${a##*.}     # .\u4ee5\u524d\u3092\u524a\u9664 (\u6700\u9577\u4e00\u81f4)\r\necho ${a%*.}      # .\u4ee5\u964d\u3092\u524a\u9664 (\u6700\u77ed\u4e00\u81f4)\r\necho ${a%%*.}     # .\u4ee5\u964d\u3092\u524a\u9664 (\u6700\u9577\u4e00\u81f4)<\/pre>\n<h2>\u6587\u5b57\u5217\u306e\u7f6e\u63db<\/h2>\n<p>\u7c21\u5358\u306a\u7f6e\u63db\u306a\u3089bash\u3067\u3002\u6b63\u898f\u8868\u73fe\u304c\u5fc5\u8981\u306a\u3082\u306e\u306fsed\u3084perl\u3092\u3069\u3046\u305e\u3002<\/p>\n<pre class=\"brush: shell;\">a=abc123.def.456\r\necho ${a\/a*f\/xyz} # a \uff5e f \u307e\u3067\u306e xyz \u306b\u7f6e\u63db\r\necho ${a\/.\/-}     # \u6700\u521d\u306e . \u3092 - \u306b\u7f6e\u63db\r\necho ${a\/\/.\/-}    # \u3059\u3079\u3066\u306e . \u3092 - \u306b\u7f6e\u63db<\/pre>\n<h2>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024<\/h2>\n<p>\u5909\u6570\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u306a\u3044\u3001\u3042\u308b\u3044\u306f\u7a7a\u306e\u5024\u304c\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u5909\u6570\u306e\u5834\u5408\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u304c\u4f7f\u308f\u308c\u308b\u3002<\/p>\n<pre class=\"brush: shell;\">unset a\r\necho ${a:-ABC} # ABC \u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/pre>\n<h2>\u305d\u306e\u4ed6<\/h2>\n<p>\u8a73\u3057\u304f\u306f man bash \u3092\u3069\u3046\u305e\u30fc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>bash\u3067\u306f\u30c9\u30eb\u8a18\u53f7\uff08$\uff09\u3067\u8272\u3005\u306a\u5834\u9762\u3067\u4f7f\u3046\uff08Bourne shell\u3067\u3082\u4f7f\u3046\u3051\u3069\uff09\u3002\u81ea\u5206\u304c\u77e5\u3063\u3066\u308b\u7bc4\u56f2\u3067\u307e\u3068\u3081\u3066\u307f\u305f\u3002 \u5909\u6570\u306e\u53c2\u7167 \u57fa\u672c\u4e2d\u306e\u57fa\u672c\u306a\u3093\u3067\u6562\u3048\u3066\u66f8\u304f\u5fc5\u8981\u306f\u306a\u3044\u304b\u3082\u3002 foo=1234 # \u5909\u6570\u306e\u5b9a\u7fa9 ech&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[32],"tags":[917],"class_list":["post-1281","post","type-post","status-publish","format-standard","hentry","category-linux-unix","tag-bash"],"_links":{"self":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/comments?post=1281"}],"version-history":[{"count":2,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1281\/revisions"}],"predecessor-version":[{"id":1283,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1281\/revisions\/1283"}],"wp:attachment":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/media?parent=1281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/categories?post=1281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/tags?post=1281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}