From 77a2f6f8a656d1ca56ce9b2f96e610d54133cfa6 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 10 Sep 2021 13:12:17 +0200 Subject: Add bash arrays --- bash.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bash.md b/bash.md index 41e8f05..e342625 100644 --- a/bash.md +++ b/bash.md @@ -53,3 +53,27 @@ Don't interpolate variables: cat << 'EOF' > file bla bla EOF + +## Arrays + +Declaring indexed arrays: + + declare -a name + +Associative arrays: + + declare -A name + +Assignment: + + array=([bla]=foo [ble]=bar...) + +All values: + + ${array[*]} # one word, elements separated with first character of $IFS + ${array[@]} # separate words when double quoted + +All keys: + + ${!array[*]} + ${!array[@]} -- cgit v1.2.3