From c0c62478fc9cdf4080e1e0fcf6774515605ef886 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 14 Jun 2018 14:32:13 +1000 Subject: [PATCH] docs: update --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7779818..b34a698 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ scripts and not full blown utilities. * [Trim quotes from a string.](#trim-quotes-from-a-string) * [Strip characters from start of string.](#strip-characters-from-start-of-string) * [Strip characters from end of string.](#strip-characters-from-end-of-string) +* [Variables](#variables) + * [Assign and access a variable using a variable.](#assign-and-access-a-variable-using-a-variable) * [Arrays](#arrays) * [Reverse an array.](#reverse-an-array) * [Remove duplicate array elements.](#remove-duplicate-array-elements) @@ -77,8 +79,8 @@ scripts and not full blown utilities. -## Strings +## Strings ### Trim white-space from string. @@ -156,6 +158,24 @@ rstrip() { } ``` +## Variables + +### Assign and access a variable using a variable. + +```sh +# Assign to a variable named after the +# value stored in '$var'. +var="test" +read -rp "input text: " "$var" + +# Access the variable indirectly. +printf '%s\n' "set var \$$var to '${!var}'" + +# Access the variable directly. +printf '%s\n' "set var \$$var to '$test'" +``` + + ## Arrays ### Reverse an array.