Skip to content

Instantly share code, notes, and snippets.

@the-ge
Forked from washingweb/README.md
Created September 13, 2024 11:44
Show Gist options
  • Save the-ge/ffebc87f2172c3bf55f7db4d6edf83cf to your computer and use it in GitHub Desktop.
Save the-ge/ffebc87f2172c3bf55f7db4d6edf83cf to your computer and use it in GitHub Desktop.
bash nameref

bash nameref

Shell Parameters

keywords

bash variable array function parameter

example

stackoverflow

#!/usr/bin/env bash

create_array() {
    local -n arr=$1              # use nameref for indirection
    arr=(one "two three" four)
}

use_array() {
    local my_array
    create_array my_array       # call function to populate the array
    echo "inside use_array"
    declare -p my_array         # test the array
}

use_array                       # call the main function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment