1、shell 脚本格式
#!/bin/bash
第一行是指定那个程序来编译执行脚本
注释是一“#”开头,shell
2、脚本执行 source、sh、bash、./执行脚本的区别
一、“. ”点命令,就是个点符号(从Bourne Shell而来)是source的另外一名称
二、source 命令(从 C Shell 而来)执行bash shell的内置命令
三、bash /bin/bash命令功能要比sh强大
四、sh /bin/sh命令
五、export可新增,修改或删除环境变量,供后续执行的程序使用。同时,重要的一点是,export的效力仅及于该次登录操做。注销或者从新开一个窗口,export命令给出的环境变量都不存在了。
export PATH=/bin/bash:$PATH
六、(点 source bash sh ./执行的文件名)他们之间的区别
6.1:点和source 执行方式是等价;即两种执行方式都是在当前shell进程中执行此脚本,而不是从新启动一个shell 而在子shell进程中执行此脚本。
6.2:bash sh (能够无执行权限)两者的执行文件不一样
./ (必须有执行权限)三者执行方式是等价的;此三种执行脚本的方式都是从新启动一个子shell,在子shell中执行此脚本。
6.3: 验证结果:bash
[root@localhost ~]#name=dangxu //定义通常变量
[root@localhost ~]# echo ${name}
dangxu
[root@localhost ~]# cat test.sh //验证脚本,实例化标题中的./*.sh
#!/bin/sh
echo ${name}
[root@localhost ~]# ls -l test.sh //验证脚本可执行
-rwxr-xr-x 1 root root 23 Feb 6 11:09 test.sh
[root@localhost ~]# ./test.sh //如下三个命令证实告终论一
[root@localhost ~]# sh ./test.sh
[root@localhost ~]# bash ./test.sh
[root@localhost ~]# . ./test.sh //如下两个命令证实告终论二
dangxu
[root@localhost ~]# source ./test.sh
dangxu
[root@localhost ~]# ide