shell 实现类似php的require_once函数
config.sh
#/bin/bash
require_once()
{
#File the true path ,To prevent a symbolic link
local realpath=$(readlink -f "$1")
local basedir=$(dirname "$realpath")
local file_full_name=$(basename "$realpath")
local file_name=$(remove_suffix "$file_full_name");
#require file once
if [ `echo "$FILE_COLLECTION"|sed -n "/$file_name/p"` ]; then
return;
fi export FILE_COLLECTION=$FILE_COLLECTION:$file_name
export PATH=$PATH:$basedir
. "$file_full_name"
}
remove_suffix()
{
local filename=$(basename "$1")
echo "$filename" | sed 's/.sh$//'
}
main.sh
#/bin/bash
. ./config.sh
require_once 'module/go.sh'
require_once 'lib/function.sh'
started
iped
test@test:/data/tmp/bak/shell$ ./main.sh
started
started
iped
shell 实现类似php的require_once函数的更多相关文章
- Shell脚本中使用function(函数)示例
这篇文章主要介绍了Shell脚本中使用function(函数)示例,本文着重讲解的是如何在shell脚本中使用自定义函数,并给出了两个例子,需要的朋友可以参考下 函数可以在shell script ...
- 【shell编程】之基础知识-函数
linux shell 可以用户定义函数,然后在shell脚本中可以随便调用. shell中函数的定义格式如下: [ function ] funname [()] { action; [return ...
- shell编程系列6--shell中的函数
shell编程系列6--shell中的函数 .函数介绍 linux shell中的函数和大多数编程语言中的函数一样 将相似的任务或者代码封装到函数中,供其他地方调用 语法格式 第一种格式 name() ...
- SQL中一种类似GUID值的函数实现
开发中会需要用到多列值组合成一个ID值的情况.比如做数据清洗的时候,一张表A有五列,分别是医院.科室.医生.职称.电话.面有许多重复的数据需要和另一个表B(和A列相同)做对比.清洗需要做两件事 ...
- shell中的内建命令, 函数和外部命令
转自shell中的内建命令, 函数和外部命令 Shell识别三种基本命令:内建命令.Shell函数以及外部命令: (1)内建命令就是由Shell本身所执行的命令. 有些命令是由于其必要性才内建的 ...
- 实现js的类似alert效果的函数
这个简单的类似alert的函数,效果还行,至于css样式,那没的说了,笔者确实尽力了,如果读者觉得太烂,你可以随便改函数的样式的,反正,笔者觉得还可以,呵呵. <!DOCTYPE html PU ...
- oracle中类似indexof用法_instr函数
oracle中类似indexof用法_instr函数 [sql] 在oracle中没有indexof()函数 但是提供了一个 instr() 方法 具体用法: select instr('保定市南市区 ...
- 实现类似printf这样的函数
来源:http://www.vimer.cn/2009/12/cc%E5%AE%9E%E7%8E%B0%E5%A4%9A%E5%8F%82%E6%95%B0%E5%87%BD%E6%95%B0%E7% ...
- 03 shell编程之case语句与函数
本文所有内容均来自当年博主当年学习笔记,若有不足欢迎指正 Shell编程之case语句与函数 学习目标: 掌握case语句编程 掌握shell函数的使用 目录结构: Case语句 Case语句的作用 ...
随机推荐
- The Story of self Parameter in Python, Demystified
转自:http://www.programiz.com/article/python-self-why If you have been programming in Python (in obj ...
- 去掉VC2010 编辑器里出现的红色波浪线
在VC2010中浏览代码的时候就大片的红线看着不舒服 其实不关VS的事,原因在于visual assist. 在VAssistX菜单栏->Visual Assist X Options-&g ...
- LeetCode 80
Remove Duplicates from Sorted Array II Follow up for "Remove Duplicates": What if duplicat ...
- 关于解决form表单记录上次保存填写记录清空
传进来的是一个HTML的Table的ID. function doReset(tableId){ var tbl_content = document.getElementById(tableId); ...
- Linux串口编程(转载)
在嵌入式Linux中,串口是一个字设备,访问具体的串行端口的编程与读/写文件 的操作类似,只需打开相应的设备文件即可操作.串口编程特殊在于串 口通信时相关参数与属性的设置.嵌入式Linux的串口编程时 ...
- toggle
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Linux 命令 - watch: 反复执行命令,全屏显示输出
watch 命令周期性地执行命令,全屏显示输出.可以通过 watch 命令反复执行某一程序来监视它的输出变化. 命令格式 watch [-dhvt] [-n <seconds>] [--d ...
- asp.net自定义控件
回发星级控件 using System; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebContro ...
- ActionBar 的简单使用
About ActionBar The action bar is one of the most important design elements you can implement for yo ...
- ubuntu 更新软件源
ubuntu 更新软件源 修改文件sources.list 位于/etc/apt/sources.list,并备份原文件为sources.list.bak deb http://mirrors.163 ...