From b16d73b5a745e43ca72959af3d4aaba79fe4bf43 Mon Sep 17 00:00:00 2001 From: Tyler Akins Date: Thu, 27 Aug 2015 09:44:04 -0500 Subject: [PATCH] Updates for how to source "mo" and then use it When you source mo, it adds the "mo" function to the environment. --- README.md | 5 +++-- demo/associative-arrays | 3 ++- demo/embedded-template | 3 ++- demo/function-for-advanced-looping | 4 ++-- demo/important-file | 3 ++- demo/using-arrays | 3 ++- demo/using-strings | 3 +++ run-tests | 3 ++- 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cd358a2..4613772 100644 --- a/README.md +++ b/README.md @@ -47,14 +47,15 @@ Using arrays adds a slight level of complexity. *You must source `mo`.* Look a #!/bin/bash cd "$(dirname "$0")" # Go to the script's directory export ARRAY=( one two "three three three" four five ) - cat << EOF | . ../mo + . ../mo # This loads the "mo" function + cat << EOF | mo Here are the items in the array: {{#ARRAY}} * {{.}} {{/ARRAY}} EOF -The result? You get a list of the five elements in the array. Take a look at the line that executes `mo`. You'll see that we went from `../mo` to using `. ../mo`. That is very important when you want arrays to work, since you can not execute a command and have arrays passed to that command's environment. Instead, we source the file. `. ../mo` is identical to `source ../mo` and you can find more about that in bash's man page. +The result? You get a list of the five elements in the array. It is vital that you source `mo` and run the function when you want arrays to work because you can not execute a command and have arrays passed to that command's environment. Instead, we first source the file to load the function and then run the function directly. There are more scripts available in the [demos directory](demo/) that could help illustrate how you would use this program. diff --git a/demo/associative-arrays b/demo/associative-arrays index 924485d..81e7f0b 100755 --- a/demo/associative-arrays +++ b/demo/associative-arrays @@ -4,8 +4,9 @@ cd "$(dirname "$0")" # Go to the script's directory declare -A DATA DATA=([one]=111 [two]=222) +. ../mo -cat < "${BASE}.diff" if [[ $? -ne 0 ]]; then