m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <m@m-chrzan.xyz>2021-09-10 13:12:17 +0200
committerMarcin Chrzanowski <m@m-chrzan.xyz>2021-09-10 13:12:17 +0200
commit77a2f6f8a656d1ca56ce9b2f96e610d54133cfa6 (patch)
treebc1d7984fb3a56c13c47a9791dc2999338821ded
parent01e06cdcffdb01f9018798414ad580896bcb8544 (diff)
Add bash arrays
-rw-r--r--bash.md24
1 files changed, 24 insertions, 0 deletions
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[@]}