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
  • 84,225
  • 14
  • 89
  • 153
Pol Hallen
  • 1,852
  • 6
  • 32
  • 44

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
  • 84,225
  • 14
  • 89
  • 153
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
  • 497,756
  • 71
  • 530
  • 681
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
  • 238,783
  • 38
  • 220
  • 352