Skip to content

Instantly share code, notes, and snippets.

@andrewgross
Created August 20, 2012 23:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewgross/3409069 to your computer and use it in GitHub Desktop.
Save andrewgross/3409069 to your computer and use it in GitHub Desktop.
Semi-Functional Programming in Bash
my_name_function() {
# There aren't many use cases where we would really want to do things this
# way instead of just using a global. Unless we are writing libraries in bash (the horror)
# or have an extremely large script where we are not sure we won't be clobbering
# variable names (equally terrifying)
local __assign_my_results_to_this_variable=$1
local do_some_work=$(echo $ALL_MY_COMMANDS_NAMES | grep -v "bad commands")
# This will take your first argument and use it as the variable name to
# which we assign the results of some other action
eval $__assign_my_results_to_this_variable="'${do_some_work}'"
}
my_outer_function() {
my_function good_commands
for command in ${good_commands}
do
# Now we call our commands, in this case with a subshell
(${command})
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment