2

Apologies if this has been answered previously, but I couldn't find much online.

Here's what I'm trying to accomplish:

if [[ "${hostname}" = (foo | bar)servername(01 | 02 | 03) ]]; then var="foobarfoo"
fi

With this any of the following would meet the criteria: fooservername01, barservername02, fooservername03, barservername03, etc.

I've accomplished this in a much more inefficient fashion:

if [[ ${hostname} == "fooservername01" ]] || [[ ${hostname} == "fooservername02" ]] || [[ ${hostname} == "fooservername03" ]] || [[ ${hostname} == "barservername01" ]] || [[ ${hostname} == "barservername02" ]] || [[ ${hostname} == "barservername03" ]]; then var="foobarfoo"
fi

But I am looking to optimize/streamline the code.

Any insight would be appreciated as I'm still very new to bash scripting and even scripting in general.

TIA

Tronyx
  • 29
  • 6

1 Answers1

-1

Found the solution in the Unix community here where I also posted this question:

https://unix.stackexchange.com/q/255036/13792

if [[ "${host}" == @(euslc|eulvs)prdapp@(05|22|23) ]]; then

Community
  • 1
  • 1
Tronyx
  • 29
  • 6