From 9bd8cdf2ecc2b60f873b393122b19985cbc4587c Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Mon, 2 Jun 2025 12:15:47 +0200 Subject: vault backup: 2025-06-02 12:15:47 --- Building a command-line using arrays.md | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Building a command-line using arrays.md (limited to 'Building a command-line using arrays.md') 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 -- cgit v1.2.3