0

I'm currently working on some bash script that's supposed to return numbers to some command. Basically, I got an array of possible variable name prefixes and I want to loop over it. While doing so I want to add a suffix and evaluate the result as a variable I set outside the loop.

Basic example:

DAYS=( "MON" "TUE" "WED" "THUR" "FRI" )   
MON_START=0800   
MON_END=1600   
TUE_START=0730   
TUE_END=1730   
....

Then the loop (not working):

for DAY in "${DAYS[@]}"; do   
    START="\${${DAY}_START}";    
    echo ${START};    
done

That, however doesn't work. It returns a "command not found" error.

Could you please help me?
Greetings, Phil.

Phil
  • 1
  • 1
    What you're looking for is called an indirect variable. See [BashFAQ #6](http://mywiki.wooledge.org/BashFAQ/006), which covers both lookup and assignment. – Charles Duffy Sep 18 '17 at 21:39
  • 1
    By the way -- all-caps names are reserved for variables with meaning to the system or shell. Your own variables should have at least one lower-case character in their names to avoid potential conflicts. See the relevant POSIX spec at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html, fourth paragraph, keeping in mind that environment variables and regular shell variables share a namespace. – Charles Duffy Sep 18 '17 at 21:40

0 Answers0