1.写一个脚本 a) 用touch命令创建一个文件:touch my_script b) 用vim编辑器打开my_script文件:vi my_script c) 用vim编辑器编辑my_script文件,内容如下: #!/bin/bash 告诉shell使用什么程序解释脚本 #My first script ls -l .* 2.允许Shell执行它 chmod 755 my_script 3.执行my_script脚本 ./my_script 转自ht
首先介绍一下shell中包含文件的方法,在C,C++,PHP中都是用include来包含文件,Go和Java使用import来包含(导入)包,而在shell中,很简单,只需要一个点“.”,然后跟着文件路径及文件名,或者使用source关键字也可以,注意文件路径可以使用绝对路径和相对路径. 下面是一个文件包含的例子:three.sh包含one.sh和two.sh #!/bin/bash #one.sh one="the is one in file one.sh" #!/bin/bash