Skip to content

Instantly share code, notes, and snippets.

@antonagestam
Created September 23, 2018 08:39
Show Gist options
  • Save antonagestam/6e0a401e33a5f237ebe48b75cad02942 to your computer and use it in GitHub Desktop.
Save antonagestam/6e0a401e33a5f237ebe48b75cad02942 to your computer and use it in GitHub Desktop.
get bash variables from a source
#!/usr/bin/env bash
set -euo pipefail
get_from () {
local file=$1
local variable=$2
echo "$(
source "$file" > /dev/null
eval "echo \"\$$variable\""
)"
}
get_from "$1" "$2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment