linux shell执行方式

linux shell执行有两种方式

shell脚本以#!/bin/bash开头,执行shell时先检查首行,在内部以下列方式执行:

$/bin/bash script.sh

1. 使用sh执行。

$sh script.sh #脚本位于当前目录下

或者

$sh /home/path/script.sh #使用完整路径

2. 独立运行脚本。

需要具备可执行权限,可以通过下面的方式设置

$chmod a+x script.sh

或者

$chmod 755 script.sh

然后可以通过下列方式执行:

$./script.sh #./表示当前目录

或者

$ /home/path/script.sh #使用完整路径

--------------------------------------------------------------------------------

附录:chmod 命令

chmod [-cfvR] [--help] [--version] mode file...

chmod owner group world FileName

● 4 – read (r)

● 2 – write (w)

● 1 – execute (x)

7 = 4+2+1 (read/write/execute)

6 = 4+2 (read/write)

5 = 4+1 (read/execute)

4 = 4 (read)

3 = 2+1 (write/execute)

2 = 2 (write)

1 = 1 (execute)

+ 表示增加权限、- 表示取消权限、= 表示唯一设定权限