Skip to content

Instantly share code, notes, and snippets.

@jcttrll
Created August 9, 2017 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcttrll/a41ad26a9176bd117374b722b58248c3 to your computer and use it in GitHub Desktop.
Save jcttrll/a41ad26a9176bd117374b722b58248c3 to your computer and use it in GitHub Desktop.
Pass-by-reference example in Bash
#!/bin/bash -e
set -o pipefail
referrer() {
local -n reference="$1"
echo "In referrer: ${!reference}"
reference=reassigned
}
passer() {
local variable=original
referrer variable
echo "Back in passer: $variable"
}
passer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment