diff --git a/demo/function-args-loops b/demo/function-args-loops new file mode 100755 index 0000000..4308966 --- /dev/null +++ b/demo/function-args-loops @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Example for how #54 can get implemented. + +cd "$(dirname "$0")" # Go to the script's directory + +# The links are associative arrays +declare -a links +declare -A names urls + +links+=(resque) +names[resque]=Resque +urls[resque]=http://example.com/resque + +links+=(hub) +names[hub]=Hub +urls[hub]=http://example.com/hub + +links+=(rip) +names[rip]=Rip +urls[rip]=http://example.com/rip + +# helper functions +link_name() { + # Trying to use unique names + local key + key=$(cat) + echo ${names[$key]} +} + +link_url() { + # Trying to use unique names + local key + key=$(cat) + echo ${urls[$key]} +} + + +# Source mo in order to work with arrays +. ../mo + +# Process the template +cat <