Created
August 20, 2012 23:11
-
-
Save andrewgross/3409069 to your computer and use it in GitHub Desktop.
Semi-Functional Programming in Bash
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
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