Created
August 10, 2019 00:38
-
-
Save fakuivan/4aedea0ddee43a1de53506bd8bcf9e68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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