0
case $location in
    ColocationOne) 
        # Define MOSES LAKE workerarray
        server[0]=serverone
        server[1]=servertwo
esac

echo ${server[0]}

How do I get this to echo: serverone ?

  • @Peschke I am echoing ${server[0]} after my initial edit. The first was a typo. I am just trying to use a variable that I declared inside the case statement from outside the case statement. – stone.212 Dec 4 '18 at 7:54
3

You set location to the string ColocationOne:

#!/bin/bash

location=ColocationOne

case $location in
    ColocationOne) 
        # Define MOSES LAKE workerarray
        server[0]=serverone
        server[1]=servertwo
        # or:  server=( serverone servertwo )
esac

echo "${server[0]}"

This script would print serverone.

| improve this answer | |
  • 1
    yes you are correct. My actual script has the quotes. My actual script referenced server[1]. My actual script had server[1] commented out. stone212 is very tired. Thank you. – stone.212 Dec 4 '18 at 7:58

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.