Skip to content

Instantly share code, notes, and snippets.

@fakuivan
Created August 10, 2019 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakuivan/4aedea0ddee43a1de53506bd8bcf9e68 to your computer and use it in GitHub Desktop.
Save fakuivan/4aedea0ddee43a1de53506bd8bcf9e68 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Returns an eval-safe representation of the bash function that when evaluated prints its name,
# useful when redefining functions
function_copy_rnd () {
local rand_prefix="$(head /dev/urandom | tr -dc A-Za-z | head -c 8)_"
local name="$1"
local decl;
decl="$(declare -f "$name")" || return $?
echo "${rand_prefix}${decl}; echo $(printf "%q" "${rand_prefix}${name}")"
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment