From ad98577c4254fc1323749f44788c670047861844 Mon Sep 17 00:00:00 2001 From: Tyler Akins Date: Mon, 13 Nov 2017 10:13:03 -0600 Subject: [PATCH] Changing how functions are called Old way: functionName CONTENT argument1 argument2 New way: echo -n "$CONTENT" | functionName argument1 argument2 This follow the Unix style more closely. --- demo/function-for-advanced-looping | 5 ++++- demo/important-file | 10 +++++++--- mo | 11 ++++++----- tests/function-args.env | 8 ++------ tests/function-args.expected | 6 +++--- tests/function.env | 4 ++-- tests/function.expected | 3 +-- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/demo/function-for-advanced-looping b/demo/function-for-advanced-looping index c097f15..b734246 100755 --- a/demo/function-for-advanced-looping +++ b/demo/function-for-advanced-looping @@ -3,6 +3,9 @@ cd "$(dirname "$0")" # Go to the script's directory EVERY_REPO() { + # The block contents come in through standard input. Capture it here. + content=$(cat) + echo "# Starting EVERY_REPO" # Get list of repos @@ -14,7 +17,7 @@ EVERY_REPO() { # 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 "$content" | sed "s/__REPO__/${REPO}/" echo "## Looped one time for repo: $REPO" done diff --git a/demo/important-file b/demo/important-file index 662697c..cd39322 100755 --- a/demo/important-file +++ b/demo/important-file @@ -2,13 +2,17 @@ cd "$(dirname "$0")"/.. -date-string() { date; } -wrapper() { echo -n "*** $1 ***"; } +date-string() { + date +} +wrapper() { + echo -n "*** $(cat) ***" +} export IP=127.0.0.1 export ALLOWED_HOSTS=( 192.168.0.1 192.168.0.2 192.168.0.3 ) -. mo # Keep in mind this script is executing in the parent directory +. ./mo # Keep in mind this script is executing in the parent directory cat <$1" + # This eats the newline in the content + echo "$(cat)" } diff --git a/tests/function.expected b/tests/function.expected index 1f1a461..d9120c0 100644 --- a/tests/function.expected +++ b/tests/function.expected @@ -1,2 +1 @@ - Willy is awesome. -... this is the last line. + Willy is awesome.... this is the last line.