shell引入其它文件函数的方法

来源:互联网 发布:网络推广炒作 编辑:程序博客网 时间:2024/05/14 19:25

无论你使用任何高级语言进行程序设计,都应该遵循分治思想,否则你的代码将会变得臃肿与难读!

本文给出shell脚本的分而治之语法,将功能分解后放入不同的shell文件中,让你的shell工程更加有条不紊,闲话少叙,下面给出例子:


1、被调用文件a.func的内容

#!/bin/bash#file to be called.#autor:wanyonghui#date:2015/10/21hello(){                echo "Hello! $1."        return }function hi(){                echo "Hi! $1."        return } 
2、调用文件b.sh的内容


#!/bin/bash#file main#autor:wanyonghui#date:2015/10/21#import file before call it. ./function.example#call hellohello lijin#call hihi maming


3、总结

采用. 文件名(绝对路径或者相对路径)引入被调用文件,语法就是这样了!


0 0