Skip to content

Instantly share code, notes, and snippets.

@unakatsuo
Last active December 21, 2015 19:08
Show Gist options
  • Save unakatsuo/6351683 to your computer and use it in GitHub Desktop.
Save unakatsuo/6351683 to your computer and use it in GitHub Desktop.
bash rename/alias function.
#!/bin/bash
function alias_function(){
[[ $(type -t "$1") = 'function' ]] || return 1;
local buf
buf="function ${2}()"
buf="${buf} $(declare -f "${1}" | tail -n +2)"
eval "$buf"
}
function a()
{
echo "BK"
}
alias_function 'a' 'b'
echo $?
type -t b
b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment