Revision 9037
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/util.sh | ||
---|---|---|
81 | 81 |
func_exists () { declare -f "$1" >/dev/null; } |
82 | 82 |
|
83 | 83 |
copy_func () # usage: from=... to=... copy_func |
84 |
# $to must not exist. to get around the no-clobber restriction, use `unset -f`. |
|
84 | 85 |
{ |
85 | 86 |
: "${from:?}" "${to:?}" |
87 |
func_exists "$from" || die "function does not exist: $from" |
|
88 |
! func_exists "$to" || die "function already exists: $to" |
|
86 | 89 |
local from_def="$(declare -f "$from")" |
87 | 90 |
eval "$to${from_def#$from}" |
88 | 91 |
} |
Also available in: Unified diff
lib/sh/util.sh: copy_func (): check that $from exists and $to does not exist (i.e. don't clobber existing functions). you can always first `unset -f` the function to get around the no-clobber restriction.