From 772f20abb0a3a0979c440114bf3a1cff5b3cef03 Mon Sep 17 00:00:00 2001 From: cvpcs Date: Wed, 2 Jun 2010 11:02:31 -0500 Subject: initial import of bash 4.1 --- examples/scripts.noah/source.bash | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 examples/scripts.noah/source.bash (limited to 'examples/scripts.noah/source.bash') diff --git a/examples/scripts.noah/source.bash b/examples/scripts.noah/source.bash new file mode 100644 index 0000000..2b36489 --- /dev/null +++ b/examples/scripts.noah/source.bash @@ -0,0 +1,63 @@ +# source.bash +# Author: Noah Friedman +# Created: 1992-05-17 +# Last modified: 1993-09-29 +# Public domain + +# Commentary: +# Code: + +#:docstring source: +# Usage: source file ... +# +# Source forces file arguments to be considered in the current directory +# only, unless there is an absolute path starting with `/'. I think it's +# bad that the builtin "source" searches PATH, because PATH normally +# contains directories with binary files that aren't useful for bash to +# read and most people don't put "." first in their path. +# +# This "source" is capable of reading more than one file at a time. Return +# value is number of failed source attempts. +#:end docstring: + +# This function is not hygienic, but there's not much we can do about +# variable name conflicts here. + +###;;;autoload +function source () +{ + local -i _source_failure_count=0 + local _source_file + + for _source_file ; do + # Check first part of each filename. If it's not `/', `./', or + # `../' then prepend "./" to the path to force the builtin `source' + # not to go searching through PATH to find the file. + case "${_source_file}" in + /*|./*|../* ) ;; + * ) _source_file="./${_source_file}" ;; + esac + + builtin source "${_source_file}" || + _source_failure_count="_source_failure_count + 1" + + done + + return ${_source_failure_count} +} + +#:docstring .: +# See "source" +#:end docstring: + +# So that `.' will call function definition of `source' instead of builtin + +###;;;autoload +function . () +{ + source "$@" +} + +provide source + +# source.bash ends here -- cgit v1.1