summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-11 01:28:20 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-11 01:28:20 +0300
commit430e95967e8968554a888cce365830bce5d46ee6 (patch)
treea80d85d6af3c0aae4ce4bba8e94ede97d732ad42
parentbash.md: arrays & `unset` (diff)
downloadnotes-430e95967e8968554a888cce365830bce5d46ee6.tar.gz
notes-430e95967e8968554a888cce365830bce5d46ee6.zip
bash.md: update
-rw-r--r--bash.md24
1 files changed, 13 insertions, 11 deletions
diff --git a/bash.md b/bash.md
index ca3c722..1ca3d13 100644
--- a/bash.md
+++ b/bash.md
@@ -6,25 +6,27 @@ GNU `bash`
### Expansion
-Yes:
+#### Do
func ${arr[@]+"${arr[@]}"}
-No:
+#### Don't
- func "${arr[@]}" # doesn't work with `nounset`
- func "${arr[@]+"${arr[@]}"}" # doesn't work with ('')
+ func "${arr[@]}" # Doesn't work with `nounset`.
+ func "${arr[@]+"${arr[@]}"}" # Doesn't work properly with `declare -a arr=('')`.
### `unset`
-Yes:
+#### Do
unset -v 'arr[$i]'
-No:
+#### Don't
- unset -v arr[x] # globbing
- unset -v arr[$i] # the same problem + quoting
- unset -v 'arr["x"]' # doesn't work for some reason
- unset -v 'arr["]"]' # the same as above; just to highlight the problem with funny characters in array indices
- # insightful discussion: https://lists.gnu.org/archive/html/help-bash/2016-09/msg00020.html
+ unset -v arr[x] # May break due to globbing.
+ unset -v arr[$i] # The same as above + possibly a pair of quotes is
+ # missing.
+ unset -v 'arr["x"]' # Doesn't work for some reason.
+ unset -v 'arr["]"]' # The same as above; just highlighting the problem
+ # with funny characters in array indices.
+ # An insightful discussion: https://lists.gnu.org/archive/html/help-bash/2016-09/msg00020.html.