# Shell

1. 书籍分享：

   introduction-to-bash-scripting

   <https://github.com/bobbyiliev/introduction-to-bash-scripting>

   书中介绍了 Shell 的基本语法特性，并用多个案例带你实战。

   虽然此书一共才122页，但内容很全面，由浅入深。值得阅读。
2. 知识分享：

   chmod: 改变文件权限

   文件权限有两种设置方法，一种是数字权限，一种是符号权限。

   Linux 文件的基本权限就有九个，分别是 **user/group/others(拥有者/组/其他)** 三种身份各有自己的 **read/write/execute** 权限。

   1. 符号权限方式：

      `chmod [-R] [u,g,o] [+,-,=] [文件或目录]`

      `-R`: 目录下的所有文件都会变更

      user/group/others(拥有者/组/其他) 分别对应的缩写为 u,g,o

      `+` 代表增加权限，`-` 代表删除权限，`=`代表设置权限

      例：`chmod u=rwx,g=rx,o=r 文件名`
   2. 数字改变权限方式

      各权限的分数对照表

      * r:4
      * w:2
      * x:1

      rwx = 4 + 2 + 1 = 7

      wx = 2 + 1 = 3 rx = 4 + 1 = 5

      rw = 4 + 2 = 6

      `chmod [-R] xyz 文件或目录`

      `-R`: 目录下的所有文件都会变更

      xyz : 就是刚刚提到的数字类型的权限属性，为 rwx 属性数值的相加。

      例：`chmod 777 .bashrc` => -rwxrwxrwx
   3. ![image-20201202194022778](https://3776288288-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPTTWwcxuzDkZnKy-OM%2Fsync%2F3b3eee6ebdaecbc33fa72a979635d0259ff57985.png?generation=1609073070725799\&alt=media)

      我就简单多了

      ![image-20201202194044134](https://3776288288-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPTTWwcxuzDkZnKy-OM%2Fsync%2F3267763119fb98245532daf0eedc557becdc6ce8.png?generation=1609073070645210\&alt=media)
   4. 快餐文分享:

      Defensive BASH Programming

      <https://kfirlavi.herokuapp.com/blog/2012/11/14/defensive-bash-programming/> 摘要: Here is my Katas for creating BASH programs that work. Nothing is new here, but from my experience pepole like to abuse BASH, forget computer science and create a [Big ball of mud](http://en.wikipedia.org/wiki/Big_ball_of_mud) from their programs. Here I provide methods to defend your programs from braking, and keep the code tidy and clean.

      由于 Shell 的糟糕设计, 作者提出了 防御性编程规范...
3. Shell的魅力

   ![image-20210206215911726](https://3776288288-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MPTTWwcxuzDkZnKy-OM%2F-MSrkPjrRXiuZMGh2q2f%2F-MSrkk-wwly3r-B7fD86%2Fimage-20210206215911726.png?alt=media\&token=03d5f51c-7a56-43f2-ad5d-b3533a3cc946)

   A: jq 不会是 jquery 吧。？

   B: 不是 Go写的 查询 json 的一个知名工具
4. sudo=速冻 cd=吃的 ls=零食 ps=披萨 ssh=熟食 scp=水产品
5. alias please=sudo
