0
#!/bin/bash
#
dm1="test1@gmail.com, test2@gmail.com, test3@gmail.com"
dm2="test4@gmail.com, test5@gmail.com, test6@gmail.com"
dm3="test7@gmail.com, test8@gmail.com, test9@gmail.com"
#
read -p "type: dm1, dm2 or dm3 to select: " blocks

I need that variable $blocks will contains not the string dm1, dm2 or dm3 but the contents of dm1, dm2 or dm3 variables to redirect to mutt to send email

Cyrus
  • 77,979
  • 13
  • 71
  • 125
Pol Hallen
  • 1,824
  • 6
  • 29
  • 43

3 Answers3

1
dm1="test1@gmail.com, test2@gmail.com, test3@gmail.com"
blocks="dm1"
echo "${!blocks}"

Output:

test1@gmail.com, test2@gmail.com, test3@gmail.com
Cyrus
  • 77,979
  • 13
  • 71
  • 125
1

Define a single array, whether indexed

dms=("test1@gmail.com, test2@gmail.com, test3@gmail.com"
     "test4@gmail.com, test5@gmail.com, test6@gmail.com"
     "test7@gmail.com, test8@gmail.com, test9@gmail.com") 

or associative

declare -A dms
dms=([dm1]="test1@gmail.com, test2@gmail.com, test3@gmail.com"
     [dm2]="test4@gmail.com, test5@gmail.com, test6@gmail.com"
     [dm3]="test7@gmail.com, test8@gmail.com, test9@gmail.com") 

Then the user can an appropriate key (or you can map the input to the appropriate key in a case statement), and you can expand "${dms[$key]}" instead.

chepner
  • 446,329
  • 63
  • 468
  • 610
0

Using select is as simple as:

PS3="Which block? "
select blocks in "$dm1" "$dm2" "$dm3"; do
  [[ $blocks ]] && break
done
echo "You selected: $blocks"
glenn jackman
  • 223,850
  • 36
  • 205
  • 328