Jonathan Hart | 518e5e7 | 2014-10-31 15:28:35 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | validate_number () { |
| 4 | local re="^[0-9]+$" |
| 5 | if [[ ! $1 =~ $re ]] ; then |
| 6 | return 1 |
| 7 | fi |
| 8 | |
| 9 | return 0 |
| 10 | } |
| 11 | |
| 12 | find_node () { |
| 13 | if validate_number $1 ; then |
| 14 | # input is a number, try to find if an OC node is defined |
| 15 | |
| 16 | oc_try="OC$1" |
| 17 | node=${!oc_try} |
| 18 | |
| 19 | if [ -n "$node" ]; then |
| 20 | # node lookup succeeded, return node |
| 21 | echo $node |
| 22 | else |
| 23 | # node lookup failed, return original input |
| 24 | echo $1 |
| 25 | fi |
| 26 | |
| 27 | else |
| 28 | echo $1 |
| 29 | fi |
| 30 | |
| 31 | return 0 |
| 32 | } |