Skip to content

Instantly share code, notes, and snippets.

@jimratliff
jimratliff / Exemplar_pass_array_to_bash_function_without_command_substitution
Last active May 29, 2018 05:12
Example: Pass array to bash function without command substitution #bash #bash_exemplar
Context:
Pass array to function, where one or more elements of the array have embedded spaces.
Goal: Have the embedded spaces respected in the array processed by the function.
############### The script
#!/usr/bin/env bash
set -eu
function echo_passed_array() {
list_of_options=("$@")
echo "List of options [0]: ${list_of_options[0]}"
echo "List of options [1]: ${list_of_options[1]}"