1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#!/bin/bash declare -A USE_MAP declare -a ENABLES # export_name dependency dependecy dependency... USE_MAP['HBASE']='USE_HBASE HCATALOG HUE' USE_MAP['PIG']='USE_PIG' USE_MAP['HUE']='USE_HUE' USE_MAP['HCATALOG']='USE_HCATALOG' USE_MAP['PRESTO']='USE_PRESTO HCATALOG' ENABLES=() function use() { local dep=(${USE_MAP["$1"]}) ENABLES+=(${dep[0]}) dep=("${dep[@]:1}") if [ ! -z "$dep" ]; then for item in ${dep[@]}; do use $item done fi } function export_enabled() { sorted_use=($(echo "${ENABLES[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) for item in ${sorted_use[@]}; do echo "export $item"; done } use HBASE export_enabled ------ $ bash resolve.sh export USE_HBASE export USE_HCATALOG export USE_HUE |