#
# set -o errexit -o noglob are assumed.
#
EXP_IFS_NL="
";
ex_basename() { echo "${1##*/}"; };
ex_date() { command date "+${1:-${TIMESTAMP_FMT}}"; };
ex_dirname() { echo "${1%/*}"; };
ex_get_var_unsafe() { eval echo \${${1}}; };
ex_set_var_unsafe() { [ -n "${2}" ] && eval ${1}=\"${2}\" || return 0; };
ex_pop_IFS() { IFS="${EXP_OLDIFS}"; };
ex_push_IFS() { EXP_OLDIFS="${IFS}"; IFS="${1}"; };
ex_push_IFS_nl() { ex_push_IFS "${EXP_IFS_NL}"; };
ex_test_cmd() { command -v "${1}" >/dev/null; };
ex_toupper() { echo "${1}" | tr a-z A-Z; };
ex_lfilter() {
[ "x${1}" = "x-not" ] && { local _notfl=1; shift; }
local _list="${1}" _filter="${2}" _lnew _litem _ex_lfilter _filterfl;
[ -z "${_filter}" ] && { echo "${_list}"; return 0; };
for _litem in ${_list}; do
_filterfl=0;
for _ex_lfilter in ${_filter}; do
if [ "${_notfl:-0}" -eq 0 ]\
&& [ "${_ex_lfilter}" = "${_litem}" ]; then
_lnew="${_lnew:+${_lnew} }${_litem}"; break;
elif [ "${_notfl:-0}" -eq 1 ]\
&& [ "${_ex_lfilter}" = "${_litem}" ]; then
_filterfl=1; break;
fi;
done;
if [ "${_notfl:-0}" -eq 1 ]\
&& [ "${_filterfl:-0}" -eq 0 ]; then
_lnew="${_lnew:+${_lnew} }${_litem}";
fi;
done;
echo "${_lnew}";
};
ex_lmatch() {
local _cmp="${3}" IFS="${2}"; set -- ${1};
while [ ${#} -gt 0 ]; do
if [ "${1}" = "${_cmp}" ]; then
return 0;
fi; shift;
done; return 1;
};
ex_run_cmd_unsplit() {
local _cmd="${1}" _cmdline _rc IFS; shift;
while [ ${#} -gt 0 ]; do
[ -n "${1}" ] &&\
_cmdline="${_cmdline:+${_cmdline}:}${1}";
shift;
done;
IFS=:; ${_cmd} ${_cmdline}; _rc=$?;
return ${_rc};
};
# vim:filetype=sh