Created
August 9, 2017 14:05
-
-
Save jcttrll/a41ad26a9176bd117374b722b58248c3 to your computer and use it in GitHub Desktop.
Pass-by-reference example in Bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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