From 140d4ec350ce4f62c968fb71026b2074019d8438 Mon Sep 17 00:00:00 2001 From: Tyler Akins Date: Tue, 5 May 2015 11:06:04 -0500 Subject: [PATCH] Adding example to illustrate how to get properties This is supporting information to demonstrate one way to address the user's issues - see issue #5. --- demo/function-for-advanced-looping | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 demo/function-for-advanced-looping diff --git a/demo/function-for-advanced-looping b/demo/function-for-advanced-looping new file mode 100755 index 0000000..49e9a1d --- /dev/null +++ b/demo/function-for-advanced-looping @@ -0,0 +1,39 @@ +#!/bin/bash + +cd "$(dirname "$0")" # Go to the script's directory + +EVERY_REPO() { + echo "# Starting EVERY_REPO" + + # Get list of repos + for REPO in "${REPOS[@]}"; do + echo "## Looping one time for repo: $REPO" + + # String replace REPO_ with the name + # This changes everything in the content block of the template. + # It rewrites {{__REPO__.name}} into {{resque.name}}, for instance. + # You can prefix your environment variables and do other things as well. + + echo -n "$1" | sed "s/__REPO__/${REPO}/" + + echo "## Looped one time for repo: $REPO" + done + + echo "# Finished EVERY_REPO" +} + +REPOS=(resque hub rip) + +declare -A resque hub rip +resque=([name]=Resque [url]=http://example.com/resque) +hub=([name]=Hub [url]=http://example.com/hub) +rip=([name]=Rip [url]=http://example.com/rip) + +cat <