第一行,声明解释器
#!/bin/bash
#!符号能够被内核识别成是一个脚本的开始,这一行必须位于脚本的首行,/bin/bash是bash程序的绝对路径,在这里表示后续的内容将通过bash程序解释执行。
Shell脚本的执行
1 输入脚本的绝对路径或相对路径
/root/helloWorld.sh
./helloWorld.sh
2 bash或sh +脚本
bash /root/helloWorld.sh
sh helloWorld.sh
3 在脚本的路径前再加". " 或source
source /root/helloWorld.sh
. ./helloWorld.sh
区别:第一种和第二种会新开一个bash,不同bash中的变量无法共享
但是使用. ./脚本.sh 这种方式是在同一个shell里面执行的。