0

I have taken over a script which is much longer than what is below. Currently you have to manually enter the environments in the export then push it to a git repo and then pull the master. I would rather use variables via numbered questions to export the choices after confirming that's what you want. e.g echo out the choices you've made and have an "are you sure Yes/No/Cancel (y/n/c)" (that part I can do).

What I can't figure out is how to capture the choices made and export them.

#!/bin/bash

clear
PS3='Please enter your choice(s): '
options=("Test" "UAT" "PreProd" "Prod" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Test")
            echo "You chose Test"
            ;;
        "UAT")
            echo "You chose UAT"
            ;;
        "PreProd")
            echo "You chose PreProd"
            ;;
        "Prod")
            echo "You chose Prod"
            ;;
        "Quit")
            break
            ;;
        *) echo invalid option;;
    esac
done



export ENVIRONMENTS=(test uat preprod)
1

Just assign the variable inside the case statement:

declare -a ENVIRONMENTS
case $opt in
    "Test")
        echo "You chose Test"
        ENVIRONMENTS+=("test")
        ;;
    "UAT")
        echo "You chose UAT"
        ENVIRONMENTS+=("uat")
        ;;
    "PreProd")
        echo "You chose PreProd"
        ENVIRONMENTS+=("preprod")
        ;;
    "Prod")
        echo "You chose Prod"
        ENVIRONMENTS+=("prod")
        ;;
    "Quit")
        break
        ;;
    *) echo invalid option;;
esac
#...
export ENVIRONMENTS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.