By default, *.sh files are opened in a text editor (Xcode or TextEdit). To create a shell script that will execute in Terminal when you open it, name it with the “command” extension, e.g., file.command. By default, these are sent to Terminal, which will execute the file as a shell script.
打开是默认自带的shell,可以通过添加前缀选择使用自己享用的shell
Note that the script does not have to begin with a #! prefix in this specific scenario, because Terminal specifically arranges to execute it with your default shell. (Of course, you can add a #! line if you want to customize which shell is used or if you want to ensure that you can execute it from the command line while using a different shell.)
Also note that Terminal executes the shell script without changing the working directory. You’ll need to begin your script with a cd command if you actually need it to run with a particular working directory.
双击可执行脚本
默认脚本会直接打开,可以使用创建
command
后缀文件,写入脚本,然后即可实现双击执行
打开是默认自带的shell,可以通过添加前缀选择使用自己享用的shell
expect脚本
expect基本说明
2
表示说进行若干次各自的匹配,所有的匹配被依次满足了之后才算整个语句完成。这一点就和前面说的tcl的命令解析方式有关了,因为第一种格式虽然占用的行数多,但是它是一个单独的expect命令,所以expect可以一次性将所有情况解析出来,然后组成一个大的并行分支;对于第二种,expect看到的只是多条单独的expect匹配,根据每个expect必须又一次匹配的原则,需要有多次匹配。总之简单的说,一个是并行关系,一个串行关系
expect pattern command expect pattern2 command2
3
它的意义同样是完成一次匹配,并且匹配之后不执行任何动作,同样是只要不匹配就继续执行。
expect pattern