shell 无法使用spawn_Shell脚本编程与运行
同传统的编程语言一样,shell提供了很多特性,这些特性可以使你的shell脚本编程更为有用。
一.创建Shell脚本
一个shell脚本通常包含如下部分:
1.首行
第一行内容在脚本的首行左侧,表示脚本将要调用的shell解释器,内容如下:
#!/bin/bash
#!符号能够被内核识别成是一个脚本的开始,这一行必须位于脚本的首行,/bin/bash是bash程序的绝对路径,在这里表示后续的内容将通过bash程序解释执行。
2.注释
注释符号# 放在需注释内容的前面,如下:

注释符号# 放在需注释内容的前面
3.内容
可执行内容和shell结构

可执行内容和shell结构
二.Shell脚本的执行
1.输入脚本的绝对路径或相对路径
/root/helloWorld.sh./helloWorld.sh
2.bash或sh +脚本
bash /root/helloWorld.shsh helloWorld.sh
注:当脚本没有x权限时,root和文件所有者通过该方式可以正常执行。
3.在脚本的路径前再加". " 或source
source /root/helloWorld.sh. ./helloWorld.sh
区别:第一种和第二种会新开一个bash,不同bash中的变量无法共享
但是使用. ./脚本.sh 这种方式是在同一个shell里面执行的。