Save function
save_function¶
Rename (copy) an existing function to a new name.
Useful for wrapping or overriding a function while preserving the original.
The original function body is copied to the new name via declare -f + eval.
Requires eval — there is no eval-free way to dynamically define a function
whose name is not known at parse time.
Example¶
# Wrap ls to always use --color
save_function ls _orig_ls
ls() { _orig_ls --color=auto "${@}"; }
Arguments¶
- $1 (string): Existing function name (source)
- $2 (string): New function name (destination)
Exit codes¶
- 0: Success; 1 Source function does not exist; 2 Missing argument