{"id":1265,"date":"2019-01-02T18:26:56","date_gmt":"2019-01-02T09:26:56","guid":{"rendered":"https:\/\/yuis-programming.com\/?p=1265"},"modified":"2021-10-17T18:24:02","modified_gmt":"2021-10-17T09:24:02","slug":"bash%e3%81%ae%e9%96%a2%e6%95%b0%e3%81%a7%e3%83%87%e3%83%95%e3%82%a9%e3%83%ab%e3%83%88%e3%81%ae%e5%bc%95%e6%95%b0","status":"publish","type":"post","link":"https:\/\/yuis-programming.com\/?p=1265","title":{"rendered":"Bash\u306e\u95a2\u6570\u3067\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u5f15\u6570"},"content":{"rendered":"<p>Linux\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u8a00\u8a9e\u306eBash\u306e\u95a2\u6570\u3067\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u5f15\u6570\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><code>random<\/code>\u3063\u3066\u95a2\u6570\u3067\u4e71\u657032\u6841\u3092\u7c21\u5358\u306b\u751f\u6210\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u305f\u3051\u3069\u3084\u3063\u3071\u6841\u6570\u6307\u5b9a\u3067\u304d\u305f\u307b\u3046\u304c\u826f\u304f\u3066\u3001\u4ee5\u4e0b\u306ealias\u3092\u3001<\/p>\n<pre><code>\nalias random=\"cat \/dev\/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1\"\n\n<\/code><\/pre>\n<p>\u3053\u3093\u306a\u3075\u3046\u306b\u6539\u826f\u3002<\/p>\n<pre><code>random(){\n  ARG1=${1:-32}\n  cat \/dev\/urandom | tr -dc 'a-zA-Z0-9' | fold -w $ARG1 | head -n 1\n}\n<\/code><\/pre>\n<p><code>random 8<\/code>\u3068\u3084\u308c\u30708\u6841\u306e\u4e71\u6570\u306b\u306a\u308b\u3002<\/p>\n<p><code>ARG1=${1:-32}<\/code>\u3067\u3001\u7b2c\u4e00\u5f15\u6570\u304c\u6307\u5b9a\u3055\u308c\u3066\u5165\u308c\u3070\u305d\u308c\u3092\u5909\u6570\u306b\u4ee3\u5165\u3057\u3001\u6307\u5b9a\u3055\u308c\u3066\u3044\u306a\u3051\u308c\u3070\u30c7\u30d5\u30a9\u30eb\u30c8\u3068\u3057\u3066<code>32<\/code>\u306e\u6570\u5024\u3092\u4ee3\u5165\u3001\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308b\u3063\u307d\u3044\u3002<\/p>\n<p><code>ARG4=${4:-$(date)}<\/code>\u306e\u3088\u3046\u306a\u30b3\u30de\u30f3\u30c9\u5c55\u958b\u3057\u3066\u4ee3\u5165\u3068\u304b\u3082\u3067\u304d\u308b\u3002<\/p>\n<p>\u95a2\u6570\u3060\u3051\u3067\u306a\u304f\u3001<code>.sh<\/code>\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057\u3066\u306e\u5f15\u6570\u306b\u5bfe\u3057\u3066\u3068\u3057\u3066\u3082\u540c\u3058\u3088\u3046\u306b\u6709\u52b9\u307f\u305f\u3044\u3002<\/p>\n<p>\u53c2\u8003\u6587\u732e:<br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/9332802\/how-to-write-a-bash-script-that-takes-optional-input-arguments\">How to write a bash script that takes optional input arguments? &#8211; Stack Overflow<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u8a00\u8a9e\u306eBash\u306e\u95a2\u6570\u3067\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u5f15\u6570\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002 random [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"acf":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8Rxwo-kp","_links":{"self":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/1265"}],"collection":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1265"}],"version-history":[{"count":2,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/1265\/revisions"}],"predecessor-version":[{"id":3055,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=\/wp\/v2\/posts\/1265\/revisions\/3055"}],"wp:attachment":[{"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yuis-programming.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}