{"action":"created","issue":{"url":"https://api.github.com/repos/echodis/mona-s-Notes/issues/5","repository_url":"https://api.github.com/repos/echodis/mona-s-Notes","labels_url":"https://api.github.com/repos/echodis/mona-s-Notes/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/echodis/mona-s-Notes/issues/5/comments","events_url":"https://api.github.com/repos/echodis/mona-s-Notes/issues/5/events","html_url":"https://github.com/echodis/mona-s-Notes/issues/5","id":315038693,"number":5,"title":"shell命令","user":{"login":"echodis","id":12342645,"avatar_url":"https://avatars0.githubusercontent.com/u/12342645?v=4","gravatar_id":"","url":"https://api.github.com/users/echodis","html_url":"https://github.com/echodis","followers_url":"https://api.github.com/users/echodis/followers","following_url":"https://api.github.com/users/echodis/following{/other_user}","gists_url":"https://api.github.com/users/echodis/gists{/gist_id}","starred_url":"https://api.github.com/users/echodis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/echodis/subscriptions","organizations_url":"https://api.github.com/users/echodis/orgs","repos_url":"https://api.github.com/users/echodis/repos","events_url":"https://api.github.com/users/echodis/events{/privacy}","received_events_url":"https://api.github.com/users/echodis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-04-17T12:33:06Z","updated_at":"2018-04-19T07:00:11Z","closed_at":null,"author_association":"OWNER","body":"Shell是一个程序，Shell脚本（shell script）是一种为shell编写的脚本程序。\r\n\r\nShell编程只要有一个能编写代码的文本编辑器和能解释执行的脚本解释器就可以了。Bash（Bourne Again Shell）是Shell的一种，是大多数linux系统默认的Shell。\r\n\r\n## Shell Start\r\n\r\n扩展名不影响脚本执行。\r\n \r\n#### 运行Shell脚本的两种方法：\r\n\r\n1 作为可执行程序\r\n\r\n```\r\nchmod +x ./test.sh #使脚本具有执行权限,`man chmod`\r\n./test.sh #执行脚本\r\n```\r\n\r\n要加上`./`，告诉系统在当前目录找。否则linux会像运行其它二进制程序一样，去PATH里找test.sh（一般都找不到）。\r\n\r\n2 作为解释器参数\r\n\r\n```\r\n/bin/sh test.sh\r\n```\r\n\r\n这种方式运行的脚本，不需要在第一行指定解释器信息。\r\n"},"comment":{"url":"https://api.github.com/repos/echodis/mona-s-Notes/issues/comments/382631609","html_url":"https://github.com/echodis/mona-s-Notes/issues/5#issuecomment-382631609","issue_url":"https://api.github.com/repos/echodis/mona-s-Notes/issues/5","id":382631609,"user":{"login":"echodis","id":12342645,"avatar_url":"https://avatars0.githubusercontent.com/u/12342645?v=4","gravatar_id":"","url":"https://api.github.com/users/echodis","html_url":"https://github.com/echodis","followers_url":"https://api.github.com/users/echodis/followers","following_url":"https://api.github.com/users/echodis/following{/other_user}","gists_url":"https://api.github.com/users/echodis/gists{/gist_id}","starred_url":"https://api.github.com/users/echodis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/echodis/subscriptions","organizations_url":"https://api.github.com/users/echodis/orgs","repos_url":"https://api.github.com/users/echodis/repos","events_url":"https://api.github.com/users/echodis/events{/privacy}","received_events_url":"https://api.github.com/users/echodis/received_events","type":"User","site_admin":false},"created_at":"2018-04-19T07:00:11Z","updated_at":"2018-04-19T07:00:11Z","author_association":"OWNER","body":"## Shell运算符\r\n\r\n原生bash不支持简单的数学运算，可以通过其他命令如`awk`、`expr`实现。\r\n\r\n#### 算数运算符\r\n\r\n```\r\nval=`expr 2 + 2`\r\necho \"两数之和为：$val\"\r\n```\r\n\r\n表达式和运算符之间要有空格，完整的表达式要被`反引号`包含。\r\n\r\n```\r\na=10\r\nb=20\r\n\r\nval=`expr $a + $b`\r\necho \"a + b : $val\"\r\n\r\nval=`expr $a - $b`\r\necho \"a - b : $val\"\r\n\r\nval=`expr $a \\* $b`\r\necho \"a * b : $val\"\r\n\r\nval=`expr $b / $a`\r\necho \"b / a : $val\"\r\n\r\nval=`expr $b % $a`\r\necho \"b % a : $val\"\r\n\r\nif [ $a == $b ]\r\nthen\r\n   echo \"a 等于 b\"\r\nfi\r\nif [ $a != $b ]\r\nthen\r\n   echo \"a 不等于 b\"\r\nfi\r\n```\r\n\r\n#### 关系运算符\r\n\r\n关系运算符只支持数字，不支持字符串（除非字符串是数字）。\r\n\r\n```\r\na=10\r\nb=20\r\n\r\nif [ $a -eq $b ]\r\nthen\r\n   echo \"$a -eq $b : a 等于 b\"\r\nelse\r\n   echo \"$a -eq $b: a 不等于 b\"\r\nfi\r\nif [ $a -ne $b ]\r\nthen\r\n   echo \"$a -ne $b: a 不等于 b\"\r\nelse\r\n   echo \"$a -ne $b : a 等于 b\"\r\nfi\r\nif [ $a -gt $b ]\r\nthen\r\n   echo \"$a -gt $b: a 大于 b\"\r\nelse\r\n   echo \"$a -gt $b: a 不大于 b\"\r\nfi\r\nif [ $a -lt $b ]\r\nthen\r\n   echo \"$a -lt $b: a 小于 b\"\r\nelse\r\n   echo \"$a -lt $b: a 不小于 b\"\r\nfi\r\nif [ $a -ge $b ]\r\nthen\r\n   echo \"$a -ge $b: a 大于或等于 b\"\r\nelse\r\n   echo \"$a -ge $b: a 小于 b\"\r\nfi\r\nif [ $a -le $b ]\r\nthen\r\n   echo \"$a -le $b: a 小于或等于 b\"\r\nelse\r\n   echo \"$a -le $b: a 大于 b\"\r\nfi\r\n```\r\n\r\n#### 布尔运算符\r\n\r\n```\r\n!：非运算\r\n-o：或运算\r\n-a：与运算\r\n```\r\n\r\n#### 逻辑运算符\r\n\r\n```\r\n&& 逻辑的AND\r\n|| 逻辑的OR\r\n```\r\n\r\n#### 字符串运算符\r\n\r\n```\r\n= 两字符串是否相等\r\n!= 两字符串是否相等\r\n-z 检测字符串长度是否为0，为0返回true\r\n-n 检测字符串长度是否为0，不为0返回true\r\nstr 检测字符串是否为空，不为空返回true\r\n```\r\n\r\n#### 文件测试运算符\r\n\r\n用于检测Unix文件的各种属性。\r\n\r\n如：\r\n\r\n```\r\n-x file：检测文件是否可执行\r\n-w file：检测文件是否可写\r\n......\r\n```"}}
{"actor":{"display_login":"echodis"}}