{"id":478,"date":"2019-05-02T04:17:16","date_gmt":"2019-05-01T19:17:16","guid":{"rendered":"https:\/\/blog.azarashi-server.com\/?p=478"},"modified":"2020-01-17T10:39:00","modified_gmt":"2020-01-17T01:39:00","slug":"post-478","status":"publish","type":"post","link":"https:\/\/blog.azarashi-server.com\/?p=478","title":{"rendered":"\u3010linux\u3011shell\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u7c21\u5358\u306a\u30b2\u30fc\u30e0\u3092\u4f5c\u3063\u3066\u307f\u3088\u3046"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u30a2\u30b6\u30e9\u30b7\u304c\u6614\u30b5\u30fc\u30d0\u30fc\u7cfb\u306e\u4f1a\u793e\u306b\u5165\u3063\u305f\u969b\u3001linux\u306e\u7814\u4fee\u306e\u3088\u3046\u306a\u3082\u306e\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3042\u307e\u308a\u306b\u5ea7\u5b66\u304c\u591a\u304f\u5bdd\u305d\u3046\u306b\u306a\u3063\u305f\u6642\u304c\u3042\u308a\u307e\u3057\u305f\u3002<br>\uff08\u3066\u3044\u3046\u304b\u307b\u307c\u5bdd\u3066\u305f\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305d\u306e\u6642\u306b\u3001\u30b3\u30bd\u30b3\u30bd\u3068\u4e00\u4eba\u3067shell\u306b\u3088\u308b\u30b2\u30fc\u30e0\u3092\u4f5c\u3063\u3066\u3044\u307e\u3057\u305f\u3002<br>\u3053\u308c\u304c\u6848\u5916shell\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u304f\u4e0a\u3067\u52c9\u5f37\u306b\u306a\u3063\u305f\u306e\u3067\u3001<br>\u5f79\u306b\u7acb\u3066\u3070\u3068\u601d\u3044\u8a18\u4e8b\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u8a18\u4e8b\u306e\u5bfe\u8c61\u8005\u3068\u3057\u3066\u306f\u3001\u4eca\u307e\u3055\u306b\u5f53\u6642\u306e\u81ea\u5206\u306e\u3088\u3046\u306b<br>linux\u3092\u52c9\u5f37\u3057\u59cb\u3081\u305f\u4eba\u3050\u3089\u3044\u306b\u898b\u3066\u3082\u3089\u3048\u305f\u3089\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b2\u30fc\u30e0\u3092\u4f5c\u308b\u306b\u3042\u305f\u3063\u3066\u3084\u308a\u65b9\u3092\u4e00\u3064\u305a\u3064\u8aac\u660e\u3057\u307e\u3059\u306e\u3067\u3001\u8a18\u4e8b\u306f\u9577\u3081\u3067\u3059\u306e\u3067\u3086\u3063\u305f\u308a\u898b\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">0.\u53c2\u8003\u306b\u3057\u305f\u30b5\u30a4\u30c8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/qiita.com\/zayarwinttun\/items\/0dae4cb66d8f4bd2a337\">\u25a0 \u521d\u5fc3\u8005\u5411\u3051\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u57fa\u672c\u30b3\u30de\u30f3\u30c9\u306e\u7d39\u4ecb<\/a><br><a href=\"https:\/\/news.mynavi.jp\/article\/20100430-shell-random-number\/\">\u25a0 \u30b7\u30a7\u30eb\u3084\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u4e71\u6570\u3092\u4f7f\u30462\u3064\u306e\u65b9\u6cd5<\/a> <br><a href=\"http:\/\/itdoc.hitachi.co.jp\/manuals\/3020\/30203S3530\/JPAS0121.HTM\">\u25a0 \u4e88\u7d04\u8a9e<\/a> <br><a href=\"https:\/\/www.atmarkit.co.jp\/ait\/articles\/1811\/28\/news003.html\">\u25a0 \u30b3\u30de\u30f3\u30c9\u3067\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u306e\u5165\u529b\u3092\u53d7\u3051\u53d6\u308b <\/a> <br><a href=\"https:\/\/qiita.com\/toshihirock\/items\/461da0f60f975f6acb10\">\u25a0 \u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(bash)\u306eif\u6587\u3068test\u30b3\u30de\u30f3\u30c9([])\u81ea\u5206\u30e1\u30e2<\/a> <br><a href=\"https:\/\/rcmdnk.com\/blog\/2018\/09\/05\/computer-bash-zsh\/\">\u25a0 \u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u6570\u5b57\u304b\u3069\u3046\u304b\u5224\u65ad\u3059\u308b\u65b9\u6cd5(expr\u3060\u3051\u3058\u3083\u306a\u3044)<\/a> <br><a href=\"https:\/\/shellscript.sunone.me\/exit_status.html\">\u25a0 \u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9<\/a> <br><a href=\"https:\/\/shellscript.sunone.me\/function.html\">\u25a0 \u95a2\u6570\u306e\u4f7f\u7528\u65b9\u6cd5<\/a><br><a href=\"https:\/\/eng-entrance.com\/linux-shellscript-while\">\u25a0\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8while\u306e\u4f7f\u3044\u65b9<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u3069\u3093\u306a\u30b2\u30fc\u30e0\u4f5c\u3063\u305f\u306e\uff1f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u5f53\u306b\u7c21\u5358\u306a\u30b2\u30fc\u30e0\u3067\u3059\u304c\u6570\u5b57\u3042\u3066\u30b2\u30fc\u30e0\u3067\u3059\u3002<br>0~9\u307e\u3067\u306e\u6570\u5b57\u3092\u5bfe\u8a71\u5f0f\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3001\u6570\u5b57\u3092\u5f53\u3066\u308b\u3088\u3046\u306a\u30b2\u30fc\u30e0\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u77e5\u8b58\u3068\u3057\u3066\u306fshell\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u4f5c\u308a\u65b9\u3001linux\u306e\u57fa\u672c\u7684\u306a\u64cd\u4f5c\u304c<br>\u3042\u308b\u7a0b\u5ea6\u308f\u304b\u3063\u3066\u3044\u308c\u3070\u30cd\u30c3\u30c8\u3067\u8abf\u3079\u3064\u3064\u3067\u304d\u308b\u3088\u3046\u306a\u30ec\u30d9\u30eb\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2.\u4f5c\u3063\u3066\u307f\u3088\u3046<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">linux\u4e0a\u3067\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u30db\u30fc\u30e0\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u4e0a\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ cd ~ ;\u30e6\u30fc\u30b6\u30fc\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5<br>$ vi numgame.sh  ;\u30b2\u30fc\u30e0\u7528shell\u30b9\u30af\u30ea\u30d7\u30c8\u30d5\u30a1\u30a4\u30eb\u3092vi\u3067\u4f5c\u6210\u3002<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u5fdc vi \u3067\u8aac\u660e\u3057\u3066\u3044\u307e\u3059\u304c\u3001vim\u304c\u4f7f\u3048\u308b\u74b0\u5883\u3067\u3042\u308b\u306a\u3089\u3070<br>vim\u306e\u307b\u3046\u304c\u826f\u3044\u3067\u3059\u3002(\u898b\u305f\u76ee\u304cvim\u306e\u65b9\u304c\u898b\u3084\u3059\u3044)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/sh<br>echo \"Hello World!\"<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u633f\u5165\u30e2\u30fc\u30c9\u3092\u89e3\u9664 :wq \u3092\u6253\u3063\u3066\u30d5\u30a1\u30a4\u30eb\u3092\u4fdd\u5b58\u3002<br>(wq\u306fwirte\u3057\u3066quit\u306e\u610f\u5473)<br>\u633f\u5165\u30e2\u30fc\u30c9\u306e\u89e3\u9664\u306f esc\u30ad\u30fc\u3067 \u633f\u5165\u30e2\u30fc\u30c9\u306b\u5165\u308b\u306e\u306f i \u3067\u3059\u3002<br><br>\u3068\u308a\u3042\u3048\u305a\u4e00\u65e6\u3053\u306e\u3088\u3046\u306a\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3057\u3087\u3046\u3002<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b21\u306b\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306b\u5b9f\u884c\u6a29\u9650\u3092\u4e0e\u3048\u307e\u3059\u3002\u5b9f\u884c\u6a29\u9650\u304c\u7121\u3044\u3068<br>\u5b9f\u884c\u3067\u304d\u306a\u3044\u306e\u3067\u3001\u4ed8\u4e0e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ chmod u+x numgame.sh<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3067\u30d5\u30a1\u30a4\u30eb\u306b\u5b9f\u884c\u6a29\u9650\u304c\u3067\u304d\u307e\u3057\u305f\u3002<br>\u30c6\u30e9\u30bf\u30fc\u30e0\u7b49\u3060\u3068\u7dd1\u8272\u306e\u6587\u5b57\u3067\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br>\u3067\u306f\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sh numgame.sh<br>Hello World!<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2\u884c\u76ee\u306e\u3088\u3046\u306b Hello World! \u3068\u51fa\u3066\u3044\u308c\u3070OK\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">numgame.sh\u306e\u8a18\u8ff0\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<br><strong>#!\/bin\/sh<\/strong><br>\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306f \u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(bash)\u3092\u4f7f\u7528\u3057\u3066\u52d5\u304d\u307e\u3059\u3002\u3068\u3044\u3046<br>\u5ba3\u8a00\u3067\u3059\u3002\u30b7\u30a7\u30eb\u306f bash,zsh,fish,csh\u7b49\u8272\u3005\u3042\u308a\u3001\u4ed6\u306e\u30b7\u30a7\u30eb\u3067\u52d5\u304b\u3057\u305f\u3044\u5834\u5408\u306f\u8a18\u8ff0\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br><strong>echo<\/strong><br>echo\u3068\u66f8\u304f\u3053\u3068\u3067\u30c6\u30ad\u30b9\u30c8\u3092\u6a19\u6e96\u51fa\u529b\u304c\u3067\u304d\u307e\u3059\u3002<br>\u7d50\u679c\u3092\u51fa\u529b\u3057\u305f\u3044\u3068\u304d\u306a\u3069\u306b\u7d50\u69cb\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2-1.\u6570\u5b57\u3042\u3066\u30b2\u30fc\u30e0\u3092\u4f5c\u308b\u8981\u4ef6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u5b57\u3042\u3066\u30b2\u30fc\u30e0\u3092\u4f5c\u308b\u306b\u3042\u305f\u3063\u3066\u3001\u5fc5\u8981\u306a\u8981\u7d20\u306f<br><strong>\u30fb0~9\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5b57\u3092\u4f5c\u308b\u3053\u3068<br>\u30fb\u5bfe\u8a71\u5f62\u5f0f\u3067\u30b2\u30fc\u30e0\u3092\u9032\u3081\u308b\u3053\u3068<br>\u30fb\u30e6\u30fc\u30b6\u30fc\u304b\u3089\u306e\u5165\u529b\u3092\u6570\u5b57\u306e\u307f\u3067\u53d7\u3051\u4ed8\u3051\u308b\u4e8b<br>\u30fb\u30e6\u30fc\u30b6\u30fc\u304b\u3089\u5165\u529b\u3055\u308c\u305f\u6570\u5b57\u304c\u7b54\u3048\u3088\u308a\u3082\u4e0a\u3082\u3057\u304f\u306f\u4e0b\u3067\u3042\u308c\u3070<br>\u3000\u305d\u306e\u65e8\u3092\u8fd4\u3059<\/strong><br><strong>\u30fb\u6b63\u89e3\u3059\u308b\u307e\u3067\u4f55\u5ea6\u3082\u5165\u529b\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<br>\u30fb\u6b63\u89e3\u3057\u305f\u3089\u4f55\u56de\u3067\u6b63\u89e3\u3057\u305f\u304b\u8868\u793a\u3057\u3001\u30b2\u30fc\u30e0\u3092\u7d42\u4e86\u3059\u308b\u304b\u518d\u5ea6\u904a\u3076\u304b\u306e<br>\u3000\u9078\u629e\u3092\u51fa\u3059\u3002<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u3059\u3002\u3053\u308c\u3060\u3051\u30ba\u30e9\u30ba\u30e9\u4e26\u3079\u308b\u3068\u96e3\u3057\u305d\u3046\u306b\u611f\u3058\u307e\u3059\u304c\u3001<br>\u3059\u3079\u3066\u8abf\u3079\u308c\u3070\u51fa\u308b\u57fa\u672c\u7684\u306a\u3082\u306e\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u4f5c\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2-2.\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5b57\u3092\u8868\u793a\u3057\u3066\u307f\u3088\u3046<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5b57\u3092\u4f5c\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u4e71\u6570\u3092\u4f7f\u7528\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<br>\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u4e71\u6570\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u8abf\u3079\u3066\u898b\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003\u30b5\u30a4\u30c8 :  <strong><a href=\"https:\/\/news.mynavi.jp\/article\/20100430-shell-random-number\/\">\u30b7\u30a7\u30eb\u3084\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u4e71\u6570\u3092\u4f7f\u30462\u3064\u306e\u65b9\u6cd5<\/a><\/strong><a href=\"https:\/\/news.mynavi.jp\/article\/20100430-shell-random-number\/\"> <\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>bash<\/strong>\u306b\u306f <strong>$RANDOM<\/strong> \u3068\u3044\u3046\u5909\u6570\u304c\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br>\u3068\u308a\u3042\u3048\u305a\u3053\u308c\u3092 echo \u3067\u51fa\u529b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br>\u5148\u7a0b\u306e\u30b2\u30fc\u30e0\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u306a\u304f\u3001cd \u3084 vim \u306a\u3069\u3092\u6253\u3064\u3044\u3064\u3082\u306e\u753b\u9762\u3067<br>\u3084\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ echo $RANDOM<br>\u30e9\u30f3\u30c0\u30e0\u306a\u81ea\u7136\u6570<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306e echo $RANDOM \u3068\u6253\u3064\u3053\u3068\u3067\u30e9\u30f3\u30c0\u30e0\u306a\u81ea\u7136\u6570\u304c\u8868\u793a\u3055\u308c\u305f\u304b\u3068\u601d\u3044\u307e\u3059\u3002\u305f\u3060\u3053\u308c\u3060\u3068\u6570\u304c 0~32767\u3068\u304b\u306a\u308a\u591a\u3044\u6570\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br>\u4eca\u56de\u306f 0~9\u3067\u751f\u6210\u3057\u305f\u3044\u306e\u3067\u5c11\u3057\u3084\u308a\u65b9\u3092\u5909\u3048\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ echo $(($RANDOM % 10))<br><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306e\u8a18\u8ff0\u3092\u3059\u308b\u3053\u3068\u3067 0~9\u306e\u6570\u5b57\u3092\u51fa\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u4f55\u3092\u3084\u3063\u3066\u3044\u308b\u304b\u3068\u3044\u3046\u3068 0~32767 \u3067\u30e9\u30f3\u30c0\u30e0\u306b\u51fa\u305f\u6570\u5b57\u3092<br>10\u3067\u5272\u308a\u3001\u4f59\u3063\u305f\u6570\u5b57\u3092\u51fa\u3057\u3066\u3044\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u306a\u306e\u3067\u4f8b\u3048\u3070 25565 \u3067\u3042\u308c\u3070 25565 \u00f7 10 = 2556 \u4f59\u308a 5<br>\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u3001\u51fa\u529b\u3055\u308c\u308b\u5024\u306f 5 \u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305f\u3060\u3053\u306e\u3084\u308a\u65b9\u306e\u554f\u984c\u306f\u3001bash\u306f 0~32767 \u306a\u306e\u3067\u7b54\u3048\u306e\u7d50\u679c\u3068\u3057\u3066<br>8,9\u304c\u6c17\u6301\u3061\u5c11\u306a\u3044\u5272\u5408\u306b\u306a\u308b\u3050\u3089\u3044\u3067\u3059\u306d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u306f\u3001\u3053\u308c\u3092\u5148\u7a0b\u4f5c\u6210\u3057\u305f numgame.sh \u306b\u5165\u308c\u8fbc\u3093\u3067\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ vim numgame.sh<br><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br><br>echo $(($RANDOM % 10))<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u7a0b\u306f<br><strong>#!\/bin\/sh<\/strong><br>\u3068\u3057\u307e\u3057\u305f\u304c\u3001bash\u72ec\u81ea\u306e $RANDOM \u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u306e\u3067<br><strong>#!\/bin\/bash<\/strong><br>\u3068\u3057\u3066bash\u72ec\u81ea\u306e\u6a5f\u80fd\u3092\u4f7f\u3044\u307e\u3059\u3068\u660e\u793a\u5316\u3057\u307e\u3057\u3087\u3046\u3002<br>(\u3053\u3046\u3057\u306a\u304f\u3066\u3082\u52d5\u304f\u3068\u306f\u601d\u3044\u307e\u3059\u304c)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u306f\u8d77\u52d5\u3057\u3066\u307f\u307e\u3057\u3087\u3046<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sh numgame.sh<br>0~9\u306e\u4e71\u6570<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3067\u3057\u3087\u3046\u304b\uff1f<br>\u306a\u3063\u3066\u306a\u3044\u5834\u5408\u306f\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u898b\u76f4\u3057\u3066\u898b\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u5b57\u3042\u3066\u30b2\u30fc\u30e0\u3092\u4f5c\u308a\u306b\u3042\u305f\u3063\u3066\u3001\u4e71\u6570\u3092\u4f5c\u308b\u3068\u3044\u3046\u90e8\u5206\u306f<br>\u307e\u305a\u306f\u30af\u30ea\u30a2\u3057\u307e\u3057\u305f\u306d\u3002\u3067\u3059\u304c\u3001\u3053\u306e\u5834\u5408\u3060\u3068<br>\u8d77\u52d5\u3057\u305f\u969b\u306b\u4e71\u6570\u3092\u751f\u6210\u3057\u3066\u7d50\u679c\u3092\u8868\u793a\u3057\u3066\u3044\u308b\u4e8b\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001<br>\u5909\u6570\u306b\u683c\u7d0d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>randomNumber=$(( $RANDOM % 10 ))<br>echo $randomNumber<br><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5909\u6570\u306f randomNumber \u306e\u3088\u3046\u306b\u308f\u304b\u308a\u3084\u3059\u3044\u540d\u524d\u3092\u3064\u3051\u307e\u3059\u3002<br>\u5909\u6570\u3092\u4f5c\u308b\u6642\u306b\u91cd\u8981\u306a\u306e\u306f \u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3082\u3068\u3082\u3068\u4f7f\u7528\u3057\u3066\u3044\u308b<br>\u540d\u524d\u306f\u3064\u3051\u3066\u306f\u3044\u3051\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u3053\u308c\u3092\u4e88\u7d04\u8a9e\u3068\u3044\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"http:\/\/itdoc.hitachi.co.jp\/manuals\/3020\/30203S3530\/JPAS0121.HTM\">\u25a0 \u4e88\u7d04\u8a9e<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306e\u30ea\u30f3\u30af\u306b\u3042\u308b\u3088\u3046\u306a case do done \u7b49\u306e\u540d\u524d\u306f\u3064\u3051\u3066\u306f\u3044\u3051\u307e\u305b\u3093\u3002<br>\u91cd\u8981\u306a\u306e\u3067\u61b6\u3048\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">randomNumber=$(($RANDOM % 10))<br>\u3068\u3059\u308b\u3053\u3068\u3067\u3001randomNumber \u3068\u3044\u3046\u5909\u6570\u306b\u4e71\u6570\u306e\u5024\u3092\u683c\u7d0d\u3067\u304d<br>\u5229\u7528\u3057\u3084\u3059\u3044\u5f62\u306b\u306a\u308a\u307e\u3059\u3002<br>\u5909\u6570\u306b\u5024\u3092\u683c\u7d0d\u3059\u308b\u6642\u306b\u91cd\u8981\u306a\u306e\u306f<br>\u5909\u6570\u540d\u3068\u683c\u7d0d\u5024\u306e\u9593\u306e = \u306e\u524d\u5f8c\u306b\u30b9\u30da\u30fc\u30b9\u3092\u5165\u308c\u3066\u306f\u3044\u3051\u307e\u305b\u3093\u3002<br>\u6b63\u3057\u304f\u5b9f\u884c\u3067\u304d\u306a\u3044\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo $randomNumber \u306e\u90e8\u5206\u3067\u3059\u304c\u3001\u5909\u6570\u3092\u51fa\u529b\u3057\u3066\u3044\u307e\u3059\u3002<br>\u5909\u6570\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306f randomNumber \u3068\u3059\u308b\u306e\u3067\u306f\u306a\u304f<br>$randomNumber \u3068\u3057\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u3001\u540c\u69d8\u306b\u4e71\u6570\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308c\u3070<br>OK\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2-3.\u5bfe\u8a71\u5f62\u5f0f\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u3066\u307f\u3088\u3046<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bfe\u8a71\u5f62\u5f0f\u30b9\u30af\u30ea\u30d7\u30c8\u3068\u306f\u3001\u5b9f\u884c\u3057\u305f\u969b\u306b<br>\u3053\u308c\u3067\u3044\u3044\u3067\u3059\u304b\uff1f(Y\/N)<br>\u306e\u3088\u3046\u306a\u3082\u306e\u304c\u51fa\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\u3002<br>yum install ~~~ \u306a\u3069\u306e\u969b\u306b<br>ok?(Y\/n)<br>\u306e\u3088\u3046\u306b\u51fa\u308b\u306e\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u7a0b\u306e\u30b2\u30fc\u30e0\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>#randomNumber=$(( $RANDOM % 10))<br><br>read -p \"\u540d\u524d\u3092\u5165\u529b\u3057\u3066\u306d : \" yourName<br>echo $yourName<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002 \u5909\u6570\u306erandomNumber\u306e\u5148\u982d\u306b #\u304c\u3064\u3044\u3066\u3044\u308b\u306e\u306f<br>\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<br># \u3053\u308c\u306f\u4e71\u6570\u3067\u3059<br>\u306e\u3088\u3046\u306b\u30b3\u30e1\u30f3\u30c8\u3092\u5165\u308c\u305f\u3044\u3068\u304d\u306f # \u3092\u5165\u308c\u305f\u308a\u3057\u307e\u3059\u3002<br>\u4ed6\u306b\u3082\u4e0a\u8a18\u306e\u3088\u3046\u306b\u4eca\u306f\u3053\u306e\u8a18\u8ff0\u3092\u4f7f\u308f\u306a\u3044\u5834\u5408\u306f<br>#\u3092\u5148\u982d\u306b\u3064\u3051\u308b\u3053\u3068\u3067\u3001\u305d\u306e\u884c\u3092\u5b9f\u884c\u3057\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u3092\u5b9f\u884c\u3059\u308b\u3068<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sh numgame.sh<br>\u540d\u524d\u3092\u5165\u529b\u3057\u3066\u306d : azarashi &lt;- \u81ea\u5206\u3067\u5165\u529b\u3057\u3001\u6700\u5f8c\u306b\u30a8\u30f3\u30bf\u30fc\u3092\u62bc\u3057\u307e\u3059\u3002<br>azarashi<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">read \u3068\u3044\u3046\u30b3\u30de\u30f3\u30c9\u306f \u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u306e\u5165\u529b\u3092\u5f85\u3061\u3001\u5165\u529b\u3055\u308c\u305f\u5185\u5bb9\u3092\u5909\u6570\u306b\u30bb\u30c3\u30c8\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003\u30b5\u30a4\u30c8 : <a href=\"https:\/\/www.atmarkit.co.jp\/ait\/articles\/1811\/28\/news003.html\">\u30b3\u30de\u30f3\u30c9\u3067\u30ad\u30fc\u30dc\u30fc\u30c9\u304b\u3089\u306e\u5165\u529b\u3092\u53d7\u3051\u53d6\u308b <\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">read \u30b3\u30de\u30f3\u30c9\u306b -p \u3068\u3044\u3046\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4ed8\u3051\u308b\u3053\u3068\u3067\u3001<br>\u540d\u524d\u3092\u5165\u529b\u3057\u3066\u306d \u3068\u3044\u3046\u90e8\u5206\u3092\u4f5c\u6210\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<br>\u3064\u3051\u306a\u3044\u5834\u5408\u306f \u4e8b\u524d\u306b echo &#8220;\u540d\u524d\u3092\u5165\u529b\u3057\u3066\u306d&#8221;<br>\u3068\u3044\u3046\u3088\u3046\u306b\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2-4. \u5165\u529b\u306e\u7d50\u679c\u306b\u3088\u3063\u3066\u51fa\u529b\u3092\u5909\u3048\u308b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u7a0b\u3001read\u30b3\u30de\u30f3\u30c9\u3067\u5bfe\u8a71\u5f0f\u5f62\u5f0f\u3067\u52d5\u304b\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<br>\u4eca\u5ea6\u306f\u53d7\u3051\u53d6\u3063\u305f\u5024\u306b\u3088\u3063\u3066\u3001\u51fa\u529b\u3092\u5909\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u5b57\u3042\u3066\u30b2\u30fc\u30e0\u3092\u4f5c\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u53d7\u3051\u53d6\u3063\u305f\u6570\u5b57\u304c<br>\u7b54\u3048\u3088\u308a\u3082\u4e0a\u304b\uff1f\u4e0b\u304b\uff1f\u6b63\u89e3\u304b\uff1f\u3068\u3044\u3046\u8fd4\u7b54\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br>\u3067\u3059\u306e\u3067\u3001\u53d7\u3051\u53d6\u3063\u305f\u6570\u5b57\u306b\u3088\u3063\u3066\u51fa\u529b\u3092\u5909\u3048\u3066\u307f\u307e\u3057\u3087\u3046<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003\u306b\u3057\u305f\u30b5\u30a4\u30c8 : <a href=\"https:\/\/qiita.com\/toshihirock\/items\/461da0f60f975f6acb10\">\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8(bash)\u306eif\u6587\u3068test\u30b3\u30de\u30f3\u30c9([])\u81ea\u5206\u30e1\u30e2<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>randomNumber=$(( $RANDOM % 10))<br><br>read -p \"\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u306d : \" reciveNumber<br><br>if [ $reciveNumber -gt $randomNumber ] ; then<br>  echo \"${reciveNumber} \u306f\u7b54\u3048\u3088\u308a\u3082\u5927\u304d\u3044\u3067\u3059\"<br>elif [ $reciveNumber -lt $randomNumber ] ; then<br>  echo \"${reciveNumber} \u306f\u7b54\u3048\u3088\u308a\u3082\u5c0f\u3055\u3044\u3067\u3059\"<br>elif [ $reciveNumber -eq $randomNumber] ; then<br>  echo \"${reciveNumber} \u306f\u7b54\u3048\u3067\u3059\uff01\"<br>fi<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">numgame.sh\u3092\u4ee5\u4e0a\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br>\u3044\u308d\u3044\u308d\u3068\u4e0d\u660e\u70b9\u304c\u3042\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u4e00\u3064\u305a\u3064\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>if [] ; then<\/strong><br>\u3053\u308c\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u57fa\u790e\u7684\u306a\u8a18\u8ff0\u3067 if \u6587\u3068\u3044\u3044\u307e\u3059\u3002<br>\u4f7f\u3044\u65b9\u3068\u3057\u3066\u306f<br>\u3082\u3057 A\u304cB\u3088\u308a\u3082\u5927\u304d\u3051\u308c\u3070\uff5e\u3084<br>\u5c0f\u3055\u3051\u308c\u3070\uff5e\u3084<br>\u4e00\u81f4\u3059\u308c\u3070\uff5e<br>\u7b49\u306e\u51e6\u7406\u3092\u3057\u305f\u3044\u6642\u306b\u4f7f\u3044\u307e\u3059\u3002<br>\u4f59\u8ac7\u3067\u3059\u304c<br>\u6700\u8fd1\u306e\u8a00\u8a9e\u3067\u3042\u308c\u3070\u5927\u4f53\u306f<br>if( a == b){<br>  <br>}<br>\u306e\u3088\u3046\u306a\u66f8\u304d\u65b9\u3067\u3059\u304c\u3001shell\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f<br>if[] ; then \u3068\u3044\u3046\u66f8\u304d\u65b9\u3092\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u306a\u306e\u3067\u3001shell\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u66f8\u304d\u65b9\u3067if\u6587\u3092\u8aac\u660e\u3059\u308b\u3068<br><br>\u3082\u3057 [ A\u304c \u5927\u304d\u3051\u308c\u3070 B\u3088\u308a\u3082 ] ; \u305d\u308c\u306a\u3089<br>\u3000\u25cb\u25cb\u3057\u307e\u3059<br>if [ $A -gt $B ] ; then<br>  echo &#8220;hogehoge&#8221;<br>\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305f\u3060\u307e\u3060\u4e0d\u660e\u70b9\u304c\u3042\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br><strong> -gt \u3063\u3066\u306a\u3093\u3060\u3088\uff01<\/strong><br>\u3067\u3059\u3088\u306d\u3002\u3053\u308c\u306f\u6570\u5f0f\u3067\u66f8\u304f\u306a\u3089<br><strong>&gt;<\/strong><br>\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u82f1\u8a9e\u3067  <br>greater than (\u3088\u308a\u3082\u5927\u304d\u3044)<br>\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3064\u307e\u308a\u4e0a\u8a18\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067<br><strong>-lt<\/strong> \u3068\u3042\u308b\u306e\u306f<br>&lt;<br>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u82f1\u8a9e\u3067<br>less than(\u3088\u308a\u3082\u5c0f\u3055\u3044)<br>\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<br><br>\u306a\u3093\u3068\u306a\u304f\u308f\u304b\u3063\u3066\u304d\u305f\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b21\u306b\u3001 <strong>elif<\/strong> \u306e\u8aac\u660e\u3092\u3057\u307e\u3059\u3002<br>if \u306f\u308f\u304b\u3063\u305f\u3051\u3069\u3001elif\u3063\u3066\u306a\u3093\u3060\u3088\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u306f else(\u305d\u308c\u4ee5\u5916\u306e) if(\u3082\u3057\u3082)<br>\u4ed6\u306e\u8a00\u8a9e\u3060\u3068 elif \u3068\u7565\u3055\u305a<br>else if(){}<br>\u3068\u3057\u3066\u4f7f\u3063\u3066\u308b\u5834\u5408\u304c\u591a\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3061\u306a\u307f\u306b\u3053\u308c\u3092\u4f7f\u308f\u305a\u3001<br>if [] ; then<br>fi<br>if [] ; then<br>fi<br>\u30fb<br>\u30fb<br>\u30fb<br>\u3068\u3057\u3066\u3084\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3058\u3083\u3042\u306a\u305c\u3084\u3089\u306a\u3044\u304b\uff1f<br>\u3053\u306e\u51e6\u7406\u306e\u65b9\u6cd5\u3060\u3068\u4f55\u304c\u554f\u984c\u306a\u306e\u304b\u3002\u305d\u308c\u306f<br>\u3059\u3079\u3066\u306eif\u3092\u6bd4\u8f03\u3059\u308b\u306e\u3067\u51e6\u7406\u3068\u3057\u3066\u30e0\u30c0\u3067\u3001<br>\u306a\u304a\u304b\u3064\u30d0\u30b0\u308b\u53ef\u80fd\u6027\u9ad8\u3044\u66f8\u304d\u65b9\u3060\u304b\u3089\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u3048\u3070\u3053\u3093\u306a\u5f0f\u304c\u3042\u3063\u305f\u3068\u3057\u307e\u3059\u3002<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u6570\u5b57=10<br>if [ \u6570\u5b57 -lt 100  ] ; then<br> echo \"\u6570\u5b57\u306f100\u3088\u308a\u5c0f\u3055\u3044\u3067\u3059\uff01\"<br>fi<br>if [\u6570\u5b57 -gt 0] ; then<br> echo \"\u6570\u5b57\u306f0\u3088\u308a\u3082\u5927\u304d\u3044\u3067\u3059\uff01\"<br>fi <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3092\u5b9f\u884c\u3059\u308b\u3068\u3069\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u304b\uff1f<br>\u7b54\u3048\u306f\u3001<br>\u6570\u5b57\u306f100\u3088\u308a\u5c0f\u3055\u3044\u3067\u3059\uff01<br>\u6570\u5b57\u306f0\u3088\u308a\u3082\u5927\u304d\u3044\u3067\u3059\uff01<br>\u3068\u51fa\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br>\u51fa\u529b\u3055\u308c\u3066\u307b\u3057\u3044\u306e\u304c\u3069\u3061\u3089\u304b\u3067\u3044\u3044\u5834\u5408\u306f\u3053\u306e\u3088\u3046\u306b\u51fa\u3066\u3057\u307e\u3046\u306e\u306f<br>\u3088\u304f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305d\u308c\u306b\u3053\u306eif\u6587\u304c\u4eca\u306f2\u500b\u3067\u3059\u304c\u30013\u500b\u30014\u500b\u30015\u500b\u30fb\u30fb\u30fb\u3068<br>\u3082\u3063\u3068\u5897\u3048\u3066\u884c\u3063\u305f\u3089\u3069\u3046\u3067\u3057\u3087\u3046\uff1f<br>\u6bce\u56de\u51e6\u7406\u3092\u3059\u308b\u305f\u3073\u4e0a\u304b\u3089\u4e00\u500b\u305a\u3064\u51e6\u7406\u3092\u3057\u3066\u3044\u3063\u305f\u3089\u3068\u3093\u3067\u3082\u306a\u304f<br>\u51e6\u7406\u304c\u5927\u5909\u3067\u3059\u3088\u306d\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305d\u3046\u3044\u3046\u3068\u304d\u306b elif \u3092\u4f7f\u3063\u3066\u3001\u4e00\u56de\u76ee\u306e\u6bd4\u8f03\u3067<br>\u8a72\u5f53\u3057\u305f\u3089\u4ed6\u306eif\u306f\u51e6\u7406\u305b\u305a if\u6587\u3092\u629c\u3051\u308b\u3068\u3044\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305f\u3060\u3001\u5fc5\u305a\u3057\u3082 elif \u3067\u3084\u3063\u305f\u307b\u3046\u304c\u826f\u3044\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u304f\u3001<br>\u51e6\u7406\u306b\u3088\u3063\u3066\u306f if &#8230; fi if &#8230; fi \u306e\u307b\u3046\u304c\u3044\u3044\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002<br>\u66f8\u304f\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u826f\u304f\u8003\u3048\u305f\u4e0a\u3067\u51e6\u7406\u3092\u5909\u3048\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3055\u3089\u3063\u3068\u8aac\u660e\u3092\u98db\u3070\u3057\u307e\u3057\u305f\u304c<br>fi \u306f \u3053\u3053\u304cif\u6587\u306e\u7d42\u308f\u308a\u3060\u3088\u3002\u3068\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3059\u3002<br>\u66f8\u304b\u306a\u3044\u3068\u30d0\u30b0\u308a\u307e\u3059\u3002<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2-5.\u6570\u5b57\u4ee5\u5916\u3092\u5165\u529b\u3055\u308c\u3066\u3057\u307e\u3063\u305f\u3089<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u3055\u3066\u3001\u5148\u7a0b\u306e\u8aac\u660e\u3067\u306f\u6570\u5b57\u3092\u5165\u308c\u308b<strong>\u524d\u63d0<\/strong>\u3067\u8a71\u3057\u3066\u307e\u3057\u305f\u304c\u3001<br>\u5b9f\u969b\u306b\u30e6\u30fc\u30b6\u30fc\u304c\u305d\u306e\u610f\u56f3\u3092\u6c72\u307f\u53d6\u3063\u3066\u6570\u5b57\u3092\u7d76\u5bfe\u5165\u308c\u308b\u3068\u306f<br>\u9650\u308a\u307e\u305b\u3093\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8a66\u3057\u306b\u5148\u7a0b\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u6587\u5b57\u3092\u5165\u308c\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">numgame.sh: 7 \u884c: [: \u3042: \u6574\u6570\u306e\u5f0f\u304c\u4e88\u671f\u3055\u308c\u307e\u3059<br>numgame.sh: 9 \u884c: [: \u3042: \u6574\u6570\u306e\u5f0f\u304c\u4e88\u671f\u3055\u308c\u307e\u3059<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(\uff89\u2200`)\uff71\uff81\uff6c\uff70<br>\u30a8\u30e9\u30fc\u3092\u5410\u304d\u307e\u3057\u305f\u306d\u30fb\u30fb\u30fb\u3002<br>\u4eca\u8a66\u3057\u306b \u3042 \u3068\u3044\u3046\u6587\u5b57\u3092\u5165\u308c\u307e\u3057\u305f\u304c\u3044\u3044\u611f\u3058\u306b\u6012\u3089\u308c\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u3059\u306e\u3067\u3001\u30b3\u30b3\u306b\u6587\u5b57\u3092\u5165\u308c\u3089\u308c\u305f\u3089<br><strong>\u6570\u5b57\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044\uff01\uff08\u6012\uff09<\/strong>\u3068\u51fa\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003\u30b5\u30a4\u30c8 : <a href=\"https:\/\/rcmdnk.com\/blog\/2018\/09\/05\/computer-bash-zsh\/\">\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u6570\u5b57\u304b\u3069\u3046\u304b\u5224\u65ad\u3059\u308b\u65b9\u6cd5(expr\u3060\u3051\u3058\u3083\u306a\u3044)<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">expr \u3092\u4f7f\u3046\u3053\u3068\u3067\u5024\u304c\u6570\u5024\u304b\u3001\u6587\u5b57\u5217\u304b\u5224\u5225\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u3053\u308c\u306f\u4e0e\u3048\u305f\u5f15\u6570\u3092\u5f0f\u3068\u3057\u3066\u8a55\u4fa1\u3057\u3066\u304f\u308c\u308b\u30c4\u30fc\u30eb\u3067\u3001\u6570\u5f0f\u306e\u8db3\u3057\u7b97\u3068\u304b\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305d\u306e\u969b\u306b\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9\u3068\u3044\u3046\u3082\u306e\u304c\u53d6\u5f97\u3067\u304d<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>0: \u5f0f\u304c\u6b63\u3057\u304f\u8a55\u4fa1\u3055\u308c\u3001\u8a55\u4fa1\u5024\u304c0\u304bnull\u4ee5\u5916\u306e\u5834\u5408<\/li><li>1: \u5f0f\u304c\u6b63\u3057\u304f\u8a55\u4fa1\u3055\u308c\u3001\u8a55\u4fa1\u5024\u304c0\u304bnull\u306e\u3068\u304d<\/li><li>2: \u5f0f\u304c\u4e0d\u5f53\u306a\u3068\u304d<\/li><li>3: (GNU\u7248\u306e\u307f)\u305d\u306e\u4ed6\u30a8\u30e9\u30fc\u304c\u8d77\u3053\u3063\u305f\u3068\u304d<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u3068\u306a\u308a\u307e\u3059\u3002\u5165\u308c\u305f\u5024\u304c2\u672a\u6e80\u3067\u3042\u308c\u3070\u57fa\u672c\u7684\u306b\u306f<br>\u6570\u5b57\u3092\u5165\u308c\u3089\u308c\u305f\u3068\u3057\u3066\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u306a\u306e\u3067\u3001\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9\u3092\u53d6\u5f97\u3057\u3066\u5224\u5225\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>randomNumber=$(( $RANDOM % 10 ))<br><br>read -p \"\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u306d : \" reciveNumber<br>expr $reciveNumber + 1 &gt; \/dev\/null 2&gt;&amp;1<br>errorCode=$?<br>echo $errorCode<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3092\u5b9f\u884c\u3057\u3066\u3000<strong>\u3042<\/strong>\u3000\u3068\u5165\u529b\u3057\u305f\u3089<br>2\u3000\u3068\u8fd4\u3063\u3066\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9\u8868\u306b\u7167\u3089\u3057\u5408\u308f\u305b\u308b\u3068\u3001<br>2:\u5f0f\u304c\u4e0d\u5f53\u306a\u3068\u304d<br>\u306b\u3042\u305f\u308a\u307e\u3057\u305f\u306d\u3002\u6210\u529f\u3067\u3059<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">expr $reciveNumber + 1<br>\u3068\u3057\u3066 $reciveNumber \u306b + 1\u3092\u3057\u3066\u5f0f\u3092\u8a55\u4fa1\u3057\u3066\u3044\u307e\u3059\u3002<br>\u305f\u3060\u3001\u3053\u306e\u307e\u307e\u5b9f\u884c\u3059\u308b\u3068<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">expr : \u6574\u6570\u3067\u306a\u3044\u5f15\u6570<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3068\u3044\u3046\u30a8\u30e9\u30fc\u51fa\u529b\u304c\u51fa\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br>\u3053\u306e\u6587\u7ae0\u3092\u51fa\u3057\u3066\u3082\u3044\u3044\u3068\u306f\u601d\u3046\u306e\u3067\u3059\u304c\u3001<br> \u6570\u5b57\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044\uff01\uff08\u6012\uff09 \u3068\u3044\u3046\u6587\u7ae0\u306b\u3057\u305f\u3044\u306e\u3067<br>\u3053\u308c\u306f\u4e0d\u8981\u3067\u3059\u306d\u3002<br>\u305d\u3046\u3044\u3046\u5834\u5408\u306f\u3053\u306e\u51fa\u529b\u3092<br>\/dev\/null<br>\u306b\u9001\u308b\u3053\u3068\u3067\u30a8\u30e9\u30fc\u51fa\u529b\u304c\u3055\u308c\u305a\/dev\/null\u306b\u9001\u3089\u308c\u307e\u3059\u3002<br>\u30a8\u30e9\u30fc\u306a\u3069\u306e\u4e0d\u8981\u306a\u51fa\u529b\u3092\u51fa\u3057\u305f\u304f\u306a\u3044\u3068\u304d\u306f<br>shell\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u5927\u62b5 \/dev\/null \u306b\u9001\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3061\u306a\u307f\u306b &gt; \u3067\u51fa\u529b\u3092\u9001\u308b\u65b9\u6cd5\u306flinux\u3067\u306f\u57fa\u672c\u306e\u3084\u308a\u65b9\u3067<br>\u3042\u307e\u308a\u8aac\u660e\u3059\u308b\u5fc5\u8981\u3082\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u4e00\u5fdc\u8aac\u660e\u3059\u308b\u3068<br>\u6a19\u6e96\u51fa\u529b\u3092\u30d5\u30a1\u30a4\u30eb\u3068\u3057\u3066\u51fa\u529b\u3057\u305f\u308a\u3059\u308b\u6642\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>$?<\/strong> \u306b\u3064\u3044\u3066\u3067\u3059\u304c<br>\u53c2\u8003\u30b5\u30a4\u30c8 : <a href=\"https:\/\/shellscript.sunone.me\/exit_status.html\">\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9<\/a><br>\u306e\u901a\u308a\u3067\u3001expr\u7b49\u306e\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9\u304c\u3042\u308b\u3082\u306e\u306f<br>linux\u3067\u3082\u3068\u3082\u3068\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9\u7528\u5909\u6570\u304c\u3042\u308a<br>\u305d\u3061\u3089\u306b\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9\u30b3\u30fc\u30c9\u304c\u683c\u7d0d\u3055\u308c\u307e\u3059\u3002<br>\u4eca\u56de\u306f\u305d\u308c\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3089\u3092\u8e0f\u307e\u3048\u305f\u4e0a\u3067\u7d42\u4e86\u30b9\u30c6\u30fc\u30bf\u30b9\u304c  0 \u3082\u3057\u304f\u306f 1\u3067\u306f\u306a\u3044\u3068\u304d\u306f<br> <strong>\u6570\u5b57\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044\uff01\uff08\u6012\uff09<\/strong> <br>\u3068\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>randomNumber=$(( $RANDOM % 10 ))<br>read -p \"\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u306d : \" reciveNumber<br>expr $reciveNumber + 1 &gt; \/dev\/null 2&gt;&amp;1<br>errorCode=$?<br><br>if [ $errorCode -ge 2 ] ; then<br> echo \"\u6570\u5b57\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044(\u6012)\"<br>fi<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sh numgame.sh<br>\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u306d : \u3042<br>\u6570\u5b57\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044\uff08\u6012\uff09<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u306e\u3088\u3046\u306a\u7d50\u679c\u306b\u306a\u308a\u307e\u3057\u305f\uff01<br>\u7121\u4e8b\u6210\u529f\u3057\u307e\u3057\u305f\u306d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3061\u306a\u307f\u306bif\u6587\u3067\u4f7f\u7528\u3057\u305f\u3001 -ge \u306f<br>grater equal(\u4ee5\u4e0a)<br>\u306a\u306e\u3067\u3001 2\u3092\u542b\u3080\u305d\u308c\u4ee5\u4e0a\u306e\u5024\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<br>\u6570\u5f0f\u3067\u8868\u3059\u306a\u3089<br>&gt;=<br>\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3061\u306a\u307f\u306b\u30fb\u30fb\u30fb<br>\u3088\u304f\u6570\u5b57\u3092\u6271\u3046\u4e0a\u3067\u306e\u4ee5\u4e0a\u3068\u4ee5\u4e0b\u3068\u672a\u6e80\u3068\u8d85\u3048\u308b\u3092\u9593\u9055\u3048\u308b\u4eba\u304c\u3044\u308b\u306e\u3067\u66f8\u3044\u3066\u304a\u304f\u3068<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u4ee5\u4e0a<\/strong>\u306f \u5024X\u3092<strong>\u542b\u3080<\/strong>\u305d\u308c\u3088\u308a\u3082\u5927\u304d\u3044\u5024\n<strong>\u4ee5\u4e0b<\/strong>\u306f \u5024X\u3092<strong>\u542b\u3080<\/strong>\u305d\u308c\u3088\u308a\u3082\u5c0f\u3055\u3044\u5024 \n<strong>\u8d85\u3048\u308b<\/strong>\u306f \u5024X\u3092<strong>\u542b\u307e\u306a\u3044<\/strong>\u305d\u308c\u3088\u308a\u3082\u5927\u304d\u3044\u5024\n<strong>\u672a\u6e80<\/strong>\u306f \u5024X\u3092<strong>\u542b\u307e\u306a\u3044<\/strong>\u305d\u308c\u3088\u308a\u5c0f\u3055\u3044\u5024<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u3059\u3002\u9593\u9055\u3048\u3066\u308b\u4eba\u304c\u3044\u305f\u3089\u9055\u3046\u3088\u3002\u3068\u6559\u3048\u3066\u4e0a\u3052\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u306f\u4eca\u307e\u3067\u306e\u3082\u306e\u3092\u304f\u3063\u3064\u3051\u3066\u3001\u6570\u5b57\u304c\u5165\u529b\u3055\u308c\u305f\u3089<br>\u6570\u5b57\u3092\u6bd4\u8f03\u3057\u3066\u3001\u305d\u308c\u306b\u5bfe\u5fdc\u3059\u308b\u51fa\u529b\u3092\u3057\u307e\u3057\u3087\u3046<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>randomNumber=$(( $RANDOM % 10 ))<br>read -p \"\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u306d : \" reciveNumber<br>expr $reciveNumber + 1 &gt; \/dev\/null 2&gt;&amp;1<br>errorCode=$?<br><br>if [ $errorCode -ge 2 ] ; then<br>  echo \"\u6570\u5b57\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044(\u6012)\"<br>else<br>  if [ $reciveNumber -gt $randomNumber ] ; then<br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3088\u308a\u3082\u5927\u304d\u3044\u3067\u3059\"<br>  elif [ $reciveNumber -lt $randomNumber ] ; then <br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3088\u308a\u3082\u5c0f\u3055\u3044\u3067\u3059\" <br>  elif [ $reciveNumber -eq $randomNumber ] ; then  <br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3067\u3059\"  <br>  fi<br>fi<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3001<br>\u3053\u308c\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u3001\u6587\u5b57\u3092\u5165\u308c\u305f\u3089\u30a8\u30e9\u30fc\u304c\u3067\u3066<br>\u6570\u5b57\u3092\u5165\u308c\u305f\u3089\u3057\u3063\u304b\u308a\u3068\u6570\u5b57\u3092\u6bd4\u8f03\u3057\u3066\u304f\u308c\u3066\u307e\u3059\uff01<br>\u3084\u3063\u305f\u30fc\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305f\u3060\u3001\u3053\u306e\u307e\u307e\u3060\u3068\u4e00\u56de\u4e00\u56de\u5b9f\u884c\u3057\u3066\u3057\u304b\u3082\u7b54\u3048\u304c\u6bce\u56de\u5909\u308f\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u4e00\u767a\u3067\u5f53\u3066\u308b\u3063\u3066\u3082\u3046\u305d\u308c\u306f\u5225\u30b2\u30fc\u611f\u304c\u3042\u308b\u306e\u3067\u3001<br>\u5f53\u3066\u308b\u307e\u3067\u4f55\u5ea6\u3082\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3001\u4f55\u56de\u76ee\u3067\u3042\u3066\u308c\u305f\u304b\u51fa\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\uff01\u30b3\u30b3\u307e\u3067\u304d\u305f\u3089\u307b\u307c\u4ed5\u4e0a\u3052\u3067\u3059<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2-6.\u6570\u5b57\u30c1\u30a7\u30c3\u30af\u51e6\u7406\u3092\u95a2\u6570\u306b\u3057\u3088\u3046<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003\u30b5\u30a4\u30c8 :<br><a href=\"https:\/\/shellscript.sunone.me\/function.html\">\u25a0 \u95a2\u6570\u306e\u4f7f\u7528\u65b9\u6cd5<\/a><br><a href=\"https:\/\/eng-entrance.com\/linux-shellscript-while\">\u25a0\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8while\u306e\u4f7f\u3044\u65b9<\/a> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f55\u5ea6\u3067\u3082\u5165\u529b\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u30eb\u30fc\u30d7\u51e6\u7406\u3092\u4f7f\u3044\u307e\u3059\u3002<br>\u30eb\u30fc\u30d7\u51e6\u7406\u3092\u3055\u305b\u308b\u306b\u306f while \u3092\u4f7f\u7528\u3057\u307e\u3059\u304c\u3001<br>\u305d\u306e\u524d\u306b\u6570\u5b57\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3001\u51fa\u529b\u3059\u308b\u90e8\u5206\u3092\u95a2\u6570\u5316\u3057\u3001<br>while \u3092\u4f7f\u3046\u6642\u306b\u308f\u304b\u308a\u3084\u3059\u3044\u3088\u3046\u306b\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>randomNumber=$(( $RANDOM % 10))<br>read -p \"\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u306d : \" reciveNumber<br><br>checkNumber(){<br>  if [ $reciveNumber -gt $randomNumber ] ; then<br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3088\u308a\u3082\u5927\u304d\u3044\u3067\u3059\"<br>  elif [ $reciveNumber -lt $randomNumber ] ; then<br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3088\u308a\u3082\u5c0f\u3055\u3044\u3067\u3059\"<br>  elif [ $reciveNumber -eq $randomNumber ] ; then<br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3067\u3059\uff01\"<br>  fi<br>}<br><br>expr $reciveNumber + 1 &gt; \/dev\/null 2&gt;&amp;1<br>errorCode=$?<br>if [ $errorCode -ge 2 ] ; then<br>  echo \"\u6570\u5b57\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044(\u6012)\"<br>else<br>  checkNumber<br>fi<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br>\u3053\u306e\u307e\u307e\u5b9f\u884c\u3057\u3066\u3082\u540c\u69d8\u306e\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<br>\u95a2\u6570\u3092\u8ffd\u52a0\u3057\u305f\u306e\u3067\u3001\u305d\u3053\u306e\u8aac\u660e\u3092\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">checkNumber(){<br>  \u51e6\u7406\u3092\u8a18\u8ff0\u3059\u308b<br>}<br>\u3053\u308c\u306f\u95a2\u6570\u3067\u3001\u540c\u3058\u3088\u3046\u306a\u51e6\u7406\u3092\u4f55\u5ea6\u3082\u547c\u3073\u51fa\u3057\u305f\u3044\u5834\u5408<br>\u4f55\u5ea6\u3082\u4f55\u5ea6\u3082\u8a18\u8ff0\u3059\u308b\u3088\u308a\u3082\u3053\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u3060\u3051\u3067<br>\u826f\u304f\u306a\u308b\u4ed6\u3001\u30b3\u30fc\u30c9\u3092\u898b\u305f\u6642\u306b\u51e6\u7406\u304c\u308f\u304b\u308a\u3084\u3059\u304f\u306a\u308b\u306e\u3067<br>\u4f7f\u3048\u308b\u3068\u304d\u306f\u4f7f\u3063\u3066\u3044\u3063\u305f\u307b\u3046\u304c\u826f\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059\u3068\u304d\u306f<br>checkNumber<br>\u3068\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u4f7f\u3048\u307e\u3059\u3002<br><br>\u5909\u6570\u306b\u95a2\u3057\u3066\u3067\u3059\u304c<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">number1=0 ; \u3053\u308c\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\nlocal number2=0 ; \u3053\u308c\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\n\ncheckNumber(){\n  local number3=0 ; \u3053\u308c\u306f\u30ed\u30fc\u30ab\u30eb\u5909\u6570\n  number\n  \n  echo $number1 ; \u6b63\u3057\u304f\u51fa\u529b\u3055\u308c\u308b\n  echo $number2 ; \u6b63\u3057\u304f\u51fa\u529b\u3055\u308c\u308b\n  echo $number3 ; \u6b63\u3057\u304f\u51fa\u529b\u3055\u308c\u308b \n}\n\necho $number1 ; \u6b63\u3057\u304f\u51fa\u529b\u3055\u308c\u308b\necho $number2 ; \u6b63\u3057\u304f\u51fa\u529b\u3055\u308c\u308b \necho $number3 ; \u51fa\u529b\u3055\u308c\u306a\u3044<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">number1 \u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3067\u3069\u3053\u3067\u53c2\u7167\u3057\u3066\u3082\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<br>local \u3092\u3064\u3051\u308b\u3068\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306b\u306a\u308a\u307e\u3059\u304c<br>local number2 \u306f numgame.sh\u306b\u5bfe\u3057\u3066\u306e\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306a\u306e\u3067\u7d50\u5c40\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3067\u3059\u3002<br>local number3 \u306f checkNumber\u5185\u3067\u306e\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306a\u306e\u3067\u3001<br>\u95a2\u6570\u3092\u629c\u3051\u3066\u3057\u307e\u3046\u3068\u53c2\u7167\u3067\u304d\u307e\u305b\u3093\u3002<br>\u30b9\u30b3\u30fc\u30d7\u304c\u9055\u3046\u3068\u53c2\u7167\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3067\u4e00\u65e6\u95a2\u6570\u306e\u6a5f\u80fd\u3068\u3057\u3066\u6570\u5b57\u306e\u30c1\u30a7\u30c3\u30af\u3092\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u306e\u3067\u3001<br>\u30eb\u30fc\u30d7\u51e6\u7406\u306b\u79fb\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2-7.\u30eb\u30fc\u30d7\u51e6\u7406<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u306f\u3044\u3088\u3044\u3088\u30eb\u30fc\u30d7\u51e6\u7406\u3067\u3059\u3002<br>\u30eb\u30fc\u30d7\u51e6\u7406\u306b\u306fwhile\u3092\u4f7f\u3044\u307e\u3059\u3002<br>\u306e\u3067\u3001\u305d\u306e\u51e6\u7406\u3092\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8af8\u3005\u30eb\u30fc\u30d7\u3067\u51e6\u7406\u3055\u305b\u308b\u306b\u3042\u305f\u3063\u3066\u30b3\u30fc\u30c9\u3092\u5909\u66f4\u3057\u3066\u308b\u306e\u3067<br>\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u306d<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br>randomNumber=$(( $RANDOM % 10 ))<br>loopBreak=false;<br><br>checkNumber() { <br>  if [ $reciveNumber -gt $randomNumber ] ; then<br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3088\u308a\u3082\u5927\u304d\u3044\u3067\u3059\"<br>  elif [ $reciveNumber -lt $randomNumber ] ; then<br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3088\u308a\u3082\u5c0f\u3055\u3044\u3067\u3059\"<br>  elif [ $reciveNumber -eq $randomNumber ] ; then<br>    echo \"${reciveNumber} \u306f\u7b54\u3048\u3067\u3059\uff01\"<br>    loopBreak=true<br>  fi <br>}<br><br>while true<br>do<br>  read -p \"\u6570\u5b57\u3092\u5165\u529b\u3057\u3066\u306d : \" reciveNumber<br>  expr $reciveNUmber + 1 &gt; \/dev\/null 2&gt;&amp;1<br>  errorCode=$?<br>  if [ $errorCode -ge 2 ] ; then<br>    echo \"\u6570\u5b57\u3092\u5165\u308c\u3066\u304f\u3060\u3055\u3044(\u6012)\"<br>  else<br>    checkNumber<br>    if $loopBreak ; then<br>      break<br>    fi<br>  fi<br>done<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">while true<br>do<br>done<br>\u3067\u3059\u304c\u3001while \u6761\u4ef6\u5f0f \u3067\u6761\u4ef6\u5f0f\u304c\u6210\u7acb\u3059\u308b\u3068\u304d\u306fdo\u306e\u5185\u5bb9\u3092<br>\u5b9f\u884c\u3057\u7d9a\u3051\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<br>\u4eca\u56de\u306f\u7121\u9650\u30eb\u30fc\u30d7\u3067\u826f\u3044\u306e\u3067 while true \u3068\u3059\u308b\u3053\u3068\u3067\u3001<br>\u6761\u4ef6\u5f0f\u306f \u771f \u3068\u306a\u308a\u7d99\u7d9a\u3057\u7d9a\u3051\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305f\u3060\u3001\u5ef6\u3005\u3068\u7d99\u7d9a\u3057\u3066\u3044\u3066\u306f\u51e6\u7406\u3092\u7d42\u308f\u3089\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<br>\u3067\u3059\u306e\u3067\u3001\u6b63\u89e3\u3057\u305f\u3089\u51e6\u7406\u3092\u629c\u3051\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">loopBreak\u3068\u3044\u3046\u5909\u6570\u306b false\u3092\u5165\u308c<br>\u6b63\u89e3\u3057\u305f\u51e6\u7406\u306e\u90e8\u5206\u3067 loopBreak=true<br>\u3068\u3044\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">do\u5185\u3067<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">checkNumber<br>if $loopBreak ; then<br>  break<br>fi <br><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">checkNuber\u306e\u51e6\u7406\u304c\u7d42\u308f\u3063\u305f\u5f8c\u306b<br>$loopBreak\u304ctrue\u3067\u3042\u308c\u3070 break\u3059\u308b\u3068\u3044\u3046\u51e6\u7406\u3092\u5165\u308c\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">break\u306fwhile\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3055\u305b\u308b\u8a18\u8ff0\u3067\u3059\u3002<br>\u3053\u308c\u3067\u7b54\u3048\u304c\u6b63\u89e3\u306b\u306a\u3063\u305f\u6642\u306bwhile\u30eb\u30fc\u30d7\u304b\u3089\u629c\u3051\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u3053\u308c\u3067\u30b2\u30fc\u30e0\u304c\u3067\u304d\u307e\u3057\u305f\uff01<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u305f\u3060\u3001while\u3092\u30d6\u30ec\u30fc\u30af\u3055\u305b\u308b\u70ba\u306b loopBreak\u3068\u3044\u3046<br>\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3092\u7528\u610f\u3059\u308b\u306e\u306f\u5c11\u3057\u5f37\u5f15\u304b\u306a\uff1f<br>\u3068\u3082\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u4ed6\u8a00\u8a9e\u3067\u3042\u308c\u3070\u3042\u308b\u7a0b\u5ea6<br>\u3084\u308a\u65b9\u3092\u308f\u304b\u3063\u3066\u3044\u308b\u3067\u3067\u304d\u308b\u306e\u3067\u3059\u304c\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306e<br>\u3044\u3044\u3084\u308a\u65b9\u304c\u601d\u3044\u3064\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002<br>while\u306e\u7d99\u7d9a\u6761\u4ef6\u5f0f\u3092loopbreak\u306b\u3057\u3066\u304a\u3051\u3070\u3088\u304b\u3063\u305f\u304b\u306a\uff1f<br>\uff08\u3044\u3044\u65b9\u6cd5\u304c\u3042\u308c\u3070\u6559\u3048\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8a66\u3057\u306b\u30b2\u30fc\u30e0\u3092\u3057\u3066\u307f\u307e\u3057\u3087\u3046<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"431\" height=\"219\" src=\"https:\/\/blog.azarashi-server.com\/wp-content\/uploads\/2019\/05\/numgame.jpg\" alt=\"\" class=\"wp-image-506\" srcset=\"https:\/\/blog.azarashi-server.com\/wp-content\/uploads\/2019\/05\/numgame.jpg 431w, https:\/\/blog.azarashi-server.com\/wp-content\/uploads\/2019\/05\/numgame-300x152.jpg 300w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\uff01<br>\u30b2\u30fc\u30e0\u3068\u3057\u3066\u904a\u3079\u3066\u3044\u307e\u3059\u306d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3.\u4f55\u56de\u76ee\u3067\u6210\u529f\u3057\u305f\u304b\u3092\u4f5c\u308b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3092\u4f5c\u308b\u306e\u306f\u5272\u3068\u7c21\u5358\u3067\u3059\u3002<br>\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3067\u30ab\u30a6\u30f3\u30c8\u3059\u308b\u5909\u6570\u3092\u7528\u610f\u3057\u3066\u3001<br>while do \u5185\u3067\u3001\u30ab\u30a6\u30f3\u30c8\u3092\u52a0\u7b97\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br>\u6700\u5f8c\u306b\u3001\u6b63\u89e3\u3057\u305f\u30b3\u30e1\u30f3\u30c8\u3092\u51fa\u3059\u90e8\u5206\u3067\u3001\u4f55\u56de\u76ee\u306b\u6210\u529f\u3057\u305f\u304b\uff1f<br>\u3092\u66f8\u3051\u3070\u3044\u3044\u3060\u3051\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30b3\u30b3\u307e\u3067\u3067\u304d\u308c\u3070\u3001\u305f\u3084\u3059\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br>\u662f\u975e\u3001\u81ea\u5206\u3067\u9811\u5f35\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4.\u4ed6\u306b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u81ea\u8eab\u304c\u7814\u4fee\u671f\u9593\u306e\u3068\u304d\u306f\u96e3\u6613\u5ea6\u3082\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<br>\u6700\u521d\u306b\u96e3\u6613\u5ea6\u30924\u3064\u7528\u610f\u3057\u3001\u96e3\u6613\u5ea6\u306b\u3088\u3063\u3066<br>\u4e71\u6570\u30920~9\u3067\u306f\u306a\u304f0~50\u306b\u3057\u305f\u308a\u3001<br>0~10000\u306b\u3057\u305f\u308a\u3057\u3066\u96e3\u6613\u5ea6\u3092\u4e0a\u3052\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3061\u306a\u307f\u306b\u3053\u306e\u30b2\u30fc\u30e0\u306f1\u6642\u9593\u7a0b\u3067\u3067\u4f5c\u308a\u307e\u3057\u305f\u3002<br>\u3042\u308b\u7a0b\u5ea6\u52c9\u5f37\u3057\u3066\u3044\u308c\u3070\u3067\u304d\u308b\u3088\u3046\u306a\u5185\u5bb9\u3060\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30a2\u30b6\u30e9\u30b7\u304c\u6614\u30b5\u30fc\u30d0\u30fc\u7cfb\u306e\u4f1a\u793e\u306b\u5165\u3063\u305f\u969b\u3001linux\u306e\u7814\u4fee\u306e\u3088\u3046\u306a\u3082\u306e\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3042\u307e\u308a\u306b\u5ea7\u5b66\u304c\u591a\u304f\u5bdd\u305d\u3046\u306b\u306a\u3063\u305f\u6642\u304c\u3042\u308a\u307e\u3057\u305f\u3002\uff08\u3066\u3044\u3046\u304b\u307b\u307c\u5bdd\u3066\u305f\uff09 \u305d\u306e\u6642\u306b\u3001\u30b3\u30bd\u30b3\u30bd\u3068\u4e00\u4eba\u3067shell\u306b\u3088\u308b\u30b2\u30fc\u30e0\u3092\u4f5c\u3063\u3066\u3044\u307e\u3057\u305f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[116,91,103,47,20],"tags":[114,117,119,118],"class_list":["post-478","post","type-post","status-publish","format-standard","hentry","category-linux","category-os","category-103","category-47","category-20","tag-linux","tag-117","tag-119","tag-118"],"views":11513,"_links":{"self":[{"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=\/wp\/v2\/posts\/478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=478"}],"version-history":[{"count":25,"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=\/wp\/v2\/posts\/478\/revisions"}],"predecessor-version":[{"id":1140,"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=\/wp\/v2\/posts\/478\/revisions\/1140"}],"wp:attachment":[{"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.azarashi-server.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}