Skip to content

Instantly share code, notes, and snippets.

@spacetrack
Last active April 15, 2016 09:56
Show Gist options
  • Save spacetrack/d9e071e2f140bf983e3ebcc658e80d32 to your computer and use it in GitHub Desktop.
Save spacetrack/d9e071e2f140bf983e3ebcc658e80d32 to your computer and use it in GitHub Desktop.
BASH Indirect Reference
#!/usr/bin/env bash
table_row_0=("Planet" "Size" "Distance")
table_row_1=("Mercury" 4879 "55")
table_row_2=("Venus" 12103 "108")
table_row_3=("Earth" 12735 "150")
table_row_4=("Mars" 6772 "228")
table_row_5=("Jupiter" 138346 "778")
table_row_6=("Saturn" 114632 "1433")
table_row_7=("Uranus" 50532 "2872")
table_row_8=("Neptune" 49105 "4495")
for (( num=0; num<9; num++ ))
do
planet_name="table_row_$num[0]"
planet_size="table_row_$num[1]"
planet_dist="table_row_$num[2]"
printf "%-20s | %6s km | %8s mio km\n" ${!planet_name} ${!planet_size} ${!planet_dist}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment