#!/bin/sh# Library routines for importing libraries# ...Usage information to go here# Only include me onceif [ "$IMPORT_LIB" ]; then returnelse IMPORT_LIB=1fi# FunctionsinitializeImport(){ LIBPATH=$PATH:${SCRIPT_DIR:+$SCRIPT_DIR:}$(dirname $0)}to_upper(){ echo $(echo $1 | tr a-z A-Z)}import(){ for arg; do mark="\$$(to_upper $arg)_LIB" already=$(eval "echo $mark") # Only import if it hasn't already been done if [ -z "$already" ]; then lib="$arg"_lib.sh pathname=$(PATH=$LIBPATH which $lib) if [ "$pathname" ]; then IMPORTING=1 source "$pathname" else echo "Error, script library $arg not found" >&2 exit 1 fi fi done}# Utilize functionality of above to search for a library# Figure out way around ugly hackimport_function(){ func=$1 ; file=$2 cmd='sed -n '"'"'/^'$func'/,/^}/p'"' $file" eval "$(echo $cmd | sh)" # eval "$(sed -n '/^f1/,/^}/p' test2.sh)"}# Always call thisinitializeImport