0

I am pretty new to BASH, had a good look around and cannot seem to get my head around the syntax for a case statement.

I basically want to allow the user to select a region and then let the case statement assign that to a variable called $region, which will be used later in the script.

Any assistance most appreciated.

echo 'u = UKI'
echo 'e = EU'
echo 'a = NA'

  read choices;
  case "$choices" in

u) region = "eu-west-2" ;;
e) region = "eu-central-2" ;;
a) region = "us-east-3" ;;
*) Invalid Choice ;;
esac

echo $region

I seem to be getting a : region: command not found error.

yardyy
  • 89
  • 8
  • 1
    Don't put spaces around the `=` in an assignment. In general, spaces are important delimiters in shell syntax, and adding or removing them often changes the meaning of a command, so don't add or remove them unless you know what the implications are. [shellcheck.net](https://www.shellcheck.net) is good at pointing out common mistakes like this (and will spot some other minor problems with your script), so I recommend running your script past it and fixing what it points out. – Gordon Davisson Sep 11 '22 at 21:58

1 Answers1

-1

You just need to remove spaces, as in bash you should use = without spaces to assign a var, like region="eu-west-2", not region = "eu-west-2"

As a result:

echo 'u = UKI'
echo 'e = EU'
echo 'a = NA'

  read choices;
  case "$choices" in

u) region="eu-west-2" ;;
e) region="eu-central-2" ;;
a) region="us-east-3" ;;
*) Invalid Choice ;;
esac

echo $region
Vadim Beskrovnov
  • 941
  • 6
  • 18