Created
November 11, 2025 01:54
-
-
Save malandro-sv/9ce8aaa20636868db73eafde8ac979ba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #! /usr/bin/env bash | |
| set_var() { | |
| # while testing and deciding whether | |
| # sourcing or executing this script: | |
| #[[ $0 != $BASH_SOURCE ]] && sourced=1 || sourced=0 | |
| #if [[ $sourced -eq 1 ]]; then | |
| # ret=return | |
| #else | |
| # ret=exit | |
| #fi | |
| #echo "Source: " $BASH_SOURCE | |
| # status code 1 if single arg is input: | |
| if [ -z "$1" ] || [ -z "$2" ]; then | |
| echo "set_var() - usage: <variable_name> <value>" | |
| echo "Exit code: 1" | |
| return 1 | |
| fi | |
| # setting up locally for further manipulation | |
| local variable="$1" | |
| local var_value="$2" | |
| # turns var into/exports as global param: | |
| declare -g -x "$variable" | |
| # assigns attr to parameter | |
| eval "${variable}='${var_value}'" | |
| echo "Variable $variable set and exported to: ${!variable}" | |
| # quick test within main shell: | |
| #env | grep $variable | |
| }; | |
| #TODO: pass $1 and $2 as | |
| # gcloud config set compute/$1 $2 | |
| # e.g: | |
| # gcloud config set compute/zone zone_name | |
| # gcloud config set compute/region region_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment