r 可读
w 可写
x 可执行
- 没有任何权限
r 读权限 read,对应数字:4
w 写权限 write,对应数字:2
x 操作权限 execute,对应数字:1
dengzemiao@dengzemiaodeMacBook-Pro shell % ls -l
total 8
---------- 1 dengzemiao staff 46 12 29 14:09 test.sh
$ chmod 777 test.sh
或
$ chmod +rwx test.sh
$ chmod 0 test.sh
$ mkdir shell
$ vim shell/test.sh
添加输出内容:
echo "Hello World"
$ cd shell/
$ ls -l
---------- 1 dengzemiao staff 46 12 29 14:09 test.sh
添加读写执行权限
$ chmod +rwx test.sh
$ sh test.sh
// 输出
Hello World
name="dzm"
echo $name
dengzemiao@dengzemiaodeMacBook-Pro shell % source test.sh
dzm
dengzemiao@dengzemiaodeMacBook-Pro shell % echo $name
dzm
dengzemiao@dengzemiaodeMacBook-Pro shell % sh test.sh
dzm
dengzemiao@dengzemiaodeMacBook-Pro shell % echo $name