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 ?

1
  • @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. Commented Dec 4, 2018 at 7:54

1 Answer 1

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.

1
  • 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. Commented Dec 4, 2018 at 7:58

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.