summaryrefslogtreecommitdiff
path: root/Building a command-line using arrays.md
diff options
context:
space:
mode:
authorJasper Ras <jras@hostnet.nl>2025-06-02 12:15:47 +0200
committerJasper Ras <jras@hostnet.nl>2025-06-02 12:17:02 +0200
commit9bd8cdf2ecc2b60f873b393122b19985cbc4587c (patch)
treea4e0ad7e2824e24b187525fc3c51f8d382d1aceb /Building a command-line using arrays.md
parenta61d928b279c5c508aca3bfc7cb14d810c3d75de (diff)
vault backup: 2025-06-02 12:15:47
Diffstat (limited to 'Building a command-line using arrays.md')
-rw-r--r--Building a command-line using arrays.md34
1 files changed, 34 insertions, 0 deletions
diff --git a/Building a command-line using arrays.md b/Building a command-line using arrays.md
new file mode 100644
index 0000000..8e187c7
--- /dev/null
+++ b/Building a command-line using arrays.md
@@ -0,0 +1,34 @@
+---
+tags:
+ - bash
+---
+[[Bash]] [[Globbing patterns]]
+
+---
+See https://www.shellcheck.net/wiki/SC2086
+
+issue with building a command-line and prevent globbing by quoting parameter expansion, solution: use array.
+
+```
+#!/usr/bin/env bash
+function test() {
+ echo "${@}"
+}
+function blaat() {
+ local flags
+ test hello "${flags[@]}"
+}
+function blaat1() {
+ local flags
+ flags=(a b c)
+ test hello "${flags[@]}"
+}
+blaat
+blaat1
+```
+
+```
+❯ bash /tmp/tmp.qI8lPlBQUe
+hello
+hello a b c
+``` \ No newline at end of file