From b0dcdb41524a59746d4c65b2a0ca559841697c4f Mon Sep 17 00:00:00 2001 From: JERIN JACOB Date: Mon, 18 Oct 2021 13:55:29 +1000 Subject: [PATCH 1/2] WEEK2CHALLENGE jerin_jacob --- .../challenge/btpguid.myscript | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/topics/Week2_Best_Practices/challenge/btpguid.myscript b/topics/Week2_Best_Practices/challenge/btpguid.myscript index 9f00cf813..20cdb07b5 100755 --- a/topics/Week2_Best_Practices/challenge/btpguid.myscript +++ b/topics/Week2_Best_Practices/challenge/btpguid.myscript @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # btpguid - return BTP subaccount/directory GUIDs # Usage: btpguid [-t|--target] displayname @@ -6,36 +8,33 @@ # specified by name. If the option -t or --target is specified, it # will also set that subaccount or directory as the target. - # Requires the btp CLI. Will direct you to log in first if you're - # not already logged in. +# Requires the btp CLI. Will direct you to log in first if you're +# not already logged in. - # It uses the detail from the output of this command: - # btp get accounts/global-account --show-hierarchy +# It uses the detail from the output of this command: +# btp get accounts/global-account --show-hierarchy # Uses the "${2:-$1}" technique seen in fff - see # https://qmacro.org/autodidactics/2021/09/03/exploring-fff-part-1-main/ # for details. - -gethier () -{ -btp get accounts/global-account --show-hierarchy 2>/dev/null +gethier() { + btp get accounts/global-account --show-hierarchy 2> /dev/null } main() { -local hierarchy subtype guid displayname rc=0 -local event=Devtoberfest + local hierarchy subtype guid displayname rc=0 displayname="${2:-$1}" - [[ -z displayname ]] && { + [[ -z $displayname ]] && { echo "No display name specified" exit 1 } hierarchy="$(gethier)" || { btp login && hierarchy="$(gethier)"; } - read subtype guid <<< "$(grep -P -o "^(subaccount|directory)\s+(\S+)(?=\s+$displayname)" <<< $hierarchy)" + read -r subtype guid <<< "$(grep -P -o "^(subaccount|directory)\s+(\S+)(?=\s+$displayname)" <<< "$hierarchy")" # Set the subtype as target if requested [[ $1 == -t ]] || [[ $1 == --target ]] && { @@ -43,7 +42,7 @@ local event=Devtoberfest rc=$? } - echo $guid + echo "$guid" return $rc } From 1830339a1c18cb9f38ce3b972be78cc0adcc0eed Mon Sep 17 00:00:00 2001 From: JERIN JACOB Date: Fri, 22 Oct 2021 08:29:39 +1000 Subject: [PATCH 2/2] Updated file name --- .../Week2_Best_Practices/challenge/{btpguid.myscript => btpguid} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename topics/Week2_Best_Practices/challenge/{btpguid.myscript => btpguid} (100%) mode change 100755 => 100644 diff --git a/topics/Week2_Best_Practices/challenge/btpguid.myscript b/topics/Week2_Best_Practices/challenge/btpguid old mode 100755 new mode 100644 similarity index 100% rename from topics/Week2_Best_Practices/challenge/btpguid.myscript rename to topics/Week2_Best_Practices/challenge/btpguid