m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <m@m-chrzan.xyz>2025-01-08 16:18:50 +0100
committerMarcin Chrzanowski <m@m-chrzan.xyz>2025-01-08 16:18:50 +0100
commitb7c68da88eec95f7705c3f4d1f0b7ba3b64abb74 (patch)
tree7f65459b6cdbc8e9e9c74ee2e829e28ec72ada39
parentf435f7d40f2fd503ca6649b417997e418edc3697 (diff)
Add bash things
-rw-r--r--bash.md30
1 files changed, 30 insertions, 0 deletions
diff --git a/bash.md b/bash.md
index 8877982..432bc5e 100644
--- a/bash.md
+++ b/bash.md
@@ -66,6 +66,9 @@ Associative arrays:
Assignment:
+ # Indexed
+ array=(foo bar "baz bom"...)
+ # Associative
array=([bla]=foo [ble]=bar...)
All values:
@@ -78,6 +81,23 @@ All keys:
${!array[*]}
${!array[@]}
+So looping:
+
+ # Over values
+ for x in "${array[@]}"; do ...
+ # Over keys (0-based indices for indexed)
+ for x in "${!array[@]}"; do ...
+
+
+Array size:
+
+ ${#array[@]}
+
+Slice:
+
+ # n elements starting at index i
+ ${array[@]:i:n}
+
## Commandline arguments
* `$#`: number of arguments.
@@ -99,3 +119,13 @@ Positional arguments will have to be supplied after flag options (`command
[options] <args>`):
shift $((OPTIND-1))
+
+
+## Shell optional behavior/settings/options (`shopt` builtin)
+
+ # Enable
+ shopt -s <option>
+ # Disable
+ shopt -u <option>
+
+* `nocaseglob`: glob matching is case insensitive